Skip to content

Commit

Permalink
Update CI
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed Sep 6, 2023
1 parent 50e99b5 commit 5203d23
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
9 changes: 6 additions & 3 deletions lib/std/threads/os/thread_posix.c3
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fn void! NativeMutex.init(&self, MutexType type)
if (posix::pthread_mutexattr_settype(&attr, posix::PTHREAD_MUTEX_RECURSIVE)) return ThreadFault.INIT_FAILED?;
}
if (posix::pthread_mutex_init(self, &attr)) return ThreadFault.INIT_FAILED?;
assert(self.is_initialized());
}

fn bool NativeMutex.is_initialized(&self)
Expand All @@ -37,11 +38,13 @@ fn void! NativeMutex.destroy(&self)
*self = NativeMutex {};
}

/**
* @require self.is_initialized() : "Mutex was not initialized"
**/
fn void! NativeMutex.lock(&self)
{
if (!self.is_initialized())
{
io::printfn("Mutex was: %s", *self);
assert(false);
}
if (posix::pthread_mutex_lock(self)) return ThreadFault.LOCK_FAILED?;
}

Expand Down
2 changes: 1 addition & 1 deletion resources/testproject/hello_world.c3
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ fn int main()
printf("Hello World!\n");
bar::test();
printf("Hello double: %d\n", test_doubler(11));
return 17;
return 0;
}
1 change: 1 addition & 0 deletions src/compiler/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ void compiler_compile(void)
printf("Launching %s...\n", output_exe);
int ret = system(platform_target.os == OS_TYPE_WIN32 ? output_exe : str_printf("./%s", output_exe));
printf("Program finished with exit code %d.\n", ret);
if (ret != 0) exit(EXIT_FAILURE);
}
}
else if (output_static)
Expand Down
11 changes: 6 additions & 5 deletions test/unit/stdlib/threads/simple_thread.c3
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@ fn void! testrun() @test
assert(t.join()! == 10);
}

Mutex m;

Mutex m_global;

fn void! testrun_mutex() @test
{
Thread[20] ts;
a = 0;
m.init()!;
m_global.init()!;
foreach (&t : ts)
{
t.create(fn int(void* arg) {
m.lock()!!;
defer m.unlock()!!;
m_global.lock()!!;
defer m_global.unlock()!!;
a += 10;
thread::sleep_ms(5);
a *= 10;
Expand All @@ -44,7 +45,7 @@ fn void! testrun_mutex() @test
assert(t.join()! == 0);
}
assert(a == ts.len);
m.destroy()!;
m_global.destroy()!;
}

fn void! testrun_mutex_try() @test
Expand Down

0 comments on commit 5203d23

Please sign in to comment.