aboutsummaryrefslogtreecommitdiff
path: root/core/thread/thread.odin
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-04-11 18:25:56 +0100
committergingerBill <bill@gingerbill.org>2021-04-11 18:25:56 +0100
commit1156bd9dd05becd536feeed90f8d33dc4cc30078 (patch)
treeb34def1f8566b43cd9d53db8e1def5632100d498 /core/thread/thread.odin
parent52c193316b3dec24ae78b6790134840536af406f (diff)
Remove thread stuff from sync2; Cleanup package thread
Diffstat (limited to 'core/thread/thread.odin')
-rw-r--r--core/thread/thread.odin69
1 files changed, 40 insertions, 29 deletions
diff --git a/core/thread/thread.odin b/core/thread/thread.odin
index 51fb116e3..fce35b124 100644
--- a/core/thread/thread.odin
+++ b/core/thread/thread.odin
@@ -26,6 +26,46 @@ Thread :: struct {
#assert(size_of(Thread{}.user_index) == size_of(uintptr));
+Thread_Priority :: enum {
+ Normal,
+ Low,
+ High,
+}
+
+create :: proc(procedure: Thread_Proc, priority := Thread_Priority.Normal) -> ^Thread {
+ return _create(procedure, priority);
+}
+destroy :: proc(thread: ^Thread) {
+ _destroy(thread);
+}
+
+start :: proc(thread: ^Thread) {
+ _start(thread);
+}
+
+is_done :: proc(thread: ^Thread) -> bool {
+ return _is_done(thread);
+}
+
+
+join :: proc(thread: ^Thread) {
+ _join(thread);
+}
+
+
+join_mulitple :: proc(threads: ..^Thread) {
+ _join_multiple(..threads);
+}
+
+terminate :: proc(thread: ^Thread, exit_code: int) {
+ _terminate(thread, exit_code);
+}
+
+yield :: proc() {
+ _yield();
+}
+
+
run :: proc(fn: proc(), init_context: Maybe(runtime.Context) = nil, priority := Thread_Priority.Normal) {
thread_proc :: proc(t: ^Thread) {
@@ -39,7 +79,6 @@ run :: proc(fn: proc(), init_context: Maybe(runtime.Context) = nil, priority :=
start(t);
}
-
run_with_data :: proc(data: rawptr, fn: proc(data: rawptr), init_context: Maybe(runtime.Context) = nil, priority := Thread_Priority.Normal) {
thread_proc :: proc(t: ^Thread) {
fn := cast(proc(rawptr))t.data;
@@ -152,31 +191,3 @@ create_and_start :: proc(fn: Thread_Proc, init_context: Maybe(runtime.Context) =
start(t);
return t;
}
-
-
-Once :: struct {
- m: sync.Blocking_Mutex,
- done: bool,
-}
-once_init :: proc(o: ^Once) {
- sync.blocking_mutex_init(&o.m);
- intrinsics.atomic_store_rel(&o.done, false);
-}
-once_destroy :: proc(o: ^Once) {
- sync.blocking_mutex_destroy(&o.m);
-}
-
-once_do :: proc(o: ^Once, fn: proc()) {
- if intrinsics.atomic_load(&o.done) == false {
- _once_do_slow(o, fn);
- }
-}
-
-_once_do_slow :: proc(o: ^Once, fn: proc()) {
- sync.blocking_mutex_lock(&o.m);
- defer sync.blocking_mutex_unlock(&o.m);
- if !o.done {
- fn();
- intrinsics.atomic_store_rel(&o.done, true);
- }
-}