mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Fix sync and thread on *nix
This commit is contained in:
@@ -81,7 +81,7 @@ condition_signal :: proc(c: ^Condition) -> bool {
|
|||||||
|
|
||||||
// Awaken all threads who are waiting on the condition
|
// Awaken all threads who are waiting on the condition
|
||||||
condition_broadcast :: proc(c: ^Condition) -> bool {
|
condition_broadcast :: proc(c: ^Condition) -> bool {
|
||||||
return pthread_cond_broadcast(&c.handle) == 0;
|
return unix.pthread_cond_broadcast(&c.handle) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for the condition to be signalled.
|
// Wait for the condition to be signalled.
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ Thread_Os_Specific :: struct #align 16 {
|
|||||||
// signal to start it.
|
// signal to start it.
|
||||||
// destroyed after thread is started.
|
// destroyed after thread is started.
|
||||||
start_gate: sync.Condition,
|
start_gate: sync.Condition,
|
||||||
|
start_mutex: sync.Mutex,
|
||||||
|
|
||||||
// if true, the thread has been started and the start_gate has been destroyed.
|
// if true, the thread has been started and the start_gate has been destroyed.
|
||||||
started: bool,
|
started: bool,
|
||||||
@@ -48,7 +49,9 @@ create :: proc(procedure: Thread_Proc, priority := Thread_Priority.Normal) -> ^T
|
|||||||
t := (^Thread)(t);
|
t := (^Thread)(t);
|
||||||
sync.condition_wait_for(&t.start_gate);
|
sync.condition_wait_for(&t.start_gate);
|
||||||
sync.condition_destroy(&t.start_gate);
|
sync.condition_destroy(&t.start_gate);
|
||||||
|
sync.mutex_destroy(&t.start_mutex);
|
||||||
t.start_gate = {};
|
t.start_gate = {};
|
||||||
|
t.start_mutex = {};
|
||||||
|
|
||||||
c := context;
|
c := context;
|
||||||
if ic, ok := t.init_context.?; ok {
|
if ic, ok := t.init_context.?; ok {
|
||||||
@@ -96,7 +99,8 @@ create :: proc(procedure: Thread_Proc, priority := Thread_Priority.Normal) -> ^T
|
|||||||
res = unix.pthread_attr_setschedparam(&attrs, ¶ms);
|
res = unix.pthread_attr_setschedparam(&attrs, ¶ms);
|
||||||
assert(res == 0);
|
assert(res == 0);
|
||||||
|
|
||||||
sync.condition_init(&thread.start_gate);
|
sync.mutex_init(&thread.start_mutex);
|
||||||
|
sync.condition_init(&thread.start_gate, &thread.start_mutex);
|
||||||
if unix.pthread_create(&thread.unix_thread, &attrs, __linux_thread_entry_proc, thread) != 0 {
|
if unix.pthread_create(&thread.unix_thread, &attrs, __linux_thread_entry_proc, thread) != 0 {
|
||||||
free(thread);
|
free(thread);
|
||||||
return nil;
|
return nil;
|
||||||
|
|||||||
Reference in New Issue
Block a user