aboutsummaryrefslogtreecommitdiff
path: root/core/thread
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2020-07-14 21:08:04 +0100
committergingerBill <bill@gingerbill.org>2020-07-14 21:08:04 +0100
commitb2beb9512f60da01072895028dc6f00c422b6ab8 (patch)
treea40615d8ee2eee1098d5eb6fd72b77cca3621c2b /core/thread
parent96ad6d2084685226886960f04182e9eea72b121f (diff)
Add thread.join_multiple
Diffstat (limited to 'core/thread')
-rw-r--r--core/thread/thread_unix.odin7
-rw-r--r--core/thread/thread_windows.odin25
2 files changed, 32 insertions, 0 deletions
diff --git a/core/thread/thread_unix.odin b/core/thread/thread_unix.odin
index b2718487a..6bf64f1e5 100644
--- a/core/thread/thread_unix.odin
+++ b/core/thread/thread_unix.odin
@@ -156,6 +156,13 @@ join :: proc(t: ^Thread) {
}
}
+join_multiple :: proc(threads: ..^Thread) {
+ for t in threads {
+ join(t);
+ }
+}
+
+
destroy :: proc(t: ^Thread) {
join(t);
t.unix_thread = {};
diff --git a/core/thread/thread_windows.odin b/core/thread/thread_windows.odin
index 5d0a4600c..749fedfb3 100644
--- a/core/thread/thread_windows.odin
+++ b/core/thread/thread_windows.odin
@@ -85,6 +85,30 @@ join :: proc(using thread: ^Thread) {
}
}
+join_multiple :: proc(threads: ..^Thread) {
+ MAXIMUM_WAIT_OBJECTS :: 64;
+
+ handles: [MAXIMUM_WAIT_OBJECTS]win32.HANDLE;
+
+ for k := 0; k < len(threads); k += MAXIMUM_WAIT_OBJECTS {
+ count := min(len(threads) - k, MAXIMUM_WAIT_OBJECTS);
+ n, j := u32(0), 0;
+ for i in 0..<count {
+ handle := threads[i+k].win32_thread;
+ if handle != win32.INVALID_HANDLE {
+ handles[j] = handle;
+ j += 1;
+ }
+ }
+ win32.WaitForMultipleObjects(n, &handles[0], true, win32.INFINITE);
+ }
+
+ for t in threads {
+ win32.CloseHandle(t.win32_thread);
+ t.win32_thread = win32.INVALID_HANDLE;
+ }
+}
+
destroy :: proc(thread: ^Thread) {
join(thread);
free(thread);
@@ -97,3 +121,4 @@ terminate :: proc(using thread : ^Thread, exit_code: u32) {
yield :: proc() {
win32.SwitchToThread();
}
+