mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-31 11:50:07 +00:00
Remove unneeded semicolons from the core library
This commit is contained in:
+93
-93
@@ -4,11 +4,11 @@ import "core:runtime"
|
||||
import "core:mem"
|
||||
import "core:intrinsics"
|
||||
|
||||
_ :: intrinsics;
|
||||
_ :: intrinsics
|
||||
|
||||
Thread_Proc :: #type proc(^Thread);
|
||||
Thread_Proc :: #type proc(^Thread)
|
||||
|
||||
MAX_USER_ARGUMENTS :: 8;
|
||||
MAX_USER_ARGUMENTS :: 8
|
||||
|
||||
Thread :: struct {
|
||||
using specific: Thread_Os_Specific,
|
||||
@@ -32,105 +32,105 @@ Thread_Priority :: enum {
|
||||
}
|
||||
|
||||
create :: proc(procedure: Thread_Proc, priority := Thread_Priority.Normal) -> ^Thread {
|
||||
return _create(procedure, priority);
|
||||
return _create(procedure, priority)
|
||||
}
|
||||
destroy :: proc(thread: ^Thread) {
|
||||
_destroy(thread);
|
||||
_destroy(thread)
|
||||
}
|
||||
|
||||
start :: proc(thread: ^Thread) {
|
||||
_start(thread);
|
||||
_start(thread)
|
||||
}
|
||||
|
||||
is_done :: proc(thread: ^Thread) -> bool {
|
||||
return _is_done(thread);
|
||||
return _is_done(thread)
|
||||
}
|
||||
|
||||
|
||||
join :: proc(thread: ^Thread) {
|
||||
_join(thread);
|
||||
_join(thread)
|
||||
}
|
||||
|
||||
|
||||
join_mulitple :: proc(threads: ..^Thread) {
|
||||
_join_multiple(..threads);
|
||||
_join_multiple(..threads)
|
||||
}
|
||||
|
||||
terminate :: proc(thread: ^Thread, exit_code: int) {
|
||||
_terminate(thread, exit_code);
|
||||
_terminate(thread, exit_code)
|
||||
}
|
||||
|
||||
yield :: proc() {
|
||||
_yield();
|
||||
_yield()
|
||||
}
|
||||
|
||||
|
||||
|
||||
run :: proc(fn: proc(), init_context: Maybe(runtime.Context) = nil, priority := Thread_Priority.Normal) {
|
||||
thread_proc :: proc(t: ^Thread) {
|
||||
fn := cast(proc())t.data;
|
||||
fn();
|
||||
destroy(t);
|
||||
fn := cast(proc())t.data
|
||||
fn()
|
||||
destroy(t)
|
||||
}
|
||||
t := create(thread_proc, priority);
|
||||
t.data = rawptr(fn);
|
||||
t.init_context = init_context;
|
||||
start(t);
|
||||
t := create(thread_proc, priority)
|
||||
t.data = rawptr(fn)
|
||||
t.init_context = init_context
|
||||
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;
|
||||
assert(t.user_index >= 1);
|
||||
data := t.user_args[0];
|
||||
fn(data);
|
||||
destroy(t);
|
||||
fn := cast(proc(rawptr))t.data
|
||||
assert(t.user_index >= 1)
|
||||
data := t.user_args[0]
|
||||
fn(data)
|
||||
destroy(t)
|
||||
}
|
||||
t := create(thread_proc, priority);
|
||||
t.data = rawptr(fn);
|
||||
t.user_index = 1;
|
||||
t.user_args = data;
|
||||
t.init_context = init_context;
|
||||
start(t);
|
||||
t := create(thread_proc, priority)
|
||||
t.data = rawptr(fn)
|
||||
t.user_index = 1
|
||||
t.user_args = data
|
||||
t.init_context = init_context
|
||||
start(t)
|
||||
}
|
||||
|
||||
run_with_poly_data :: proc(data: $T, fn: proc(data: T), init_context: Maybe(runtime.Context) = nil, priority := Thread_Priority.Normal)
|
||||
where size_of(T) <= size_of(rawptr) {
|
||||
thread_proc :: proc(t: ^Thread) {
|
||||
fn := cast(proc(T))t.data;
|
||||
assert(t.user_index >= 1);
|
||||
data := (^T)(&t.user_args[0])^;
|
||||
fn(data);
|
||||
destroy(t);
|
||||
fn := cast(proc(T))t.data
|
||||
assert(t.user_index >= 1)
|
||||
data := (^T)(&t.user_args[0])^
|
||||
fn(data)
|
||||
destroy(t)
|
||||
}
|
||||
t := create(thread_proc, priority);
|
||||
t.data = rawptr(fn);
|
||||
t.user_index = 1;
|
||||
data := data;
|
||||
mem.copy(&t.user_args[0], &data, size_of(data));
|
||||
t.init_context = init_context;
|
||||
start(t);
|
||||
t := create(thread_proc, priority)
|
||||
t.data = rawptr(fn)
|
||||
t.user_index = 1
|
||||
data := data
|
||||
mem.copy(&t.user_args[0], &data, size_of(data))
|
||||
t.init_context = init_context
|
||||
start(t)
|
||||
}
|
||||
|
||||
run_with_poly_data2 :: proc(arg1: $T1, arg2: $T2, fn: proc(T1, T2), init_context: Maybe(runtime.Context) = nil, priority := Thread_Priority.Normal)
|
||||
where size_of(T1) <= size_of(rawptr),
|
||||
size_of(T2) <= size_of(rawptr) {
|
||||
thread_proc :: proc(t: ^Thread) {
|
||||
fn := cast(proc(T1, T2))t.data;
|
||||
assert(t.user_index >= 2);
|
||||
arg1 := (^T1)(&t.user_args[0])^;
|
||||
arg2 := (^T2)(&t.user_args[1])^;
|
||||
fn(arg1, arg2);
|
||||
destroy(t);
|
||||
fn := cast(proc(T1, T2))t.data
|
||||
assert(t.user_index >= 2)
|
||||
arg1 := (^T1)(&t.user_args[0])^
|
||||
arg2 := (^T2)(&t.user_args[1])^
|
||||
fn(arg1, arg2)
|
||||
destroy(t)
|
||||
}
|
||||
t := create(thread_proc, priority);
|
||||
t.data = rawptr(fn);
|
||||
t.user_index = 2;
|
||||
arg1, arg2 := arg1, arg2;
|
||||
mem.copy(&t.user_args[0], &arg1, size_of(arg1));
|
||||
mem.copy(&t.user_args[1], &arg2, size_of(arg2));
|
||||
t.init_context = init_context;
|
||||
start(t);
|
||||
t := create(thread_proc, priority)
|
||||
t.data = rawptr(fn)
|
||||
t.user_index = 2
|
||||
arg1, arg2 := arg1, arg2
|
||||
mem.copy(&t.user_args[0], &arg1, size_of(arg1))
|
||||
mem.copy(&t.user_args[1], &arg2, size_of(arg2))
|
||||
t.init_context = init_context
|
||||
start(t)
|
||||
}
|
||||
|
||||
run_with_poly_data3 :: proc(arg1: $T1, arg2: $T2, arg3: $T3, fn: proc(arg1: T1, arg2: T2, arg3: T3), init_context: Maybe(runtime.Context) = nil, priority := Thread_Priority.Normal)
|
||||
@@ -138,55 +138,55 @@ run_with_poly_data3 :: proc(arg1: $T1, arg2: $T2, arg3: $T3, fn: proc(arg1: T1,
|
||||
size_of(T2) <= size_of(rawptr),
|
||||
size_of(T3) <= size_of(rawptr) {
|
||||
thread_proc :: proc(t: ^Thread) {
|
||||
fn := cast(proc(T1, T2, T3))t.data;
|
||||
assert(t.user_index >= 3);
|
||||
arg1 := (^T1)(&t.user_args[0])^;
|
||||
arg2 := (^T2)(&t.user_args[1])^;
|
||||
arg3 := (^T3)(&t.user_args[2])^;
|
||||
fn(arg1, arg2, arg3);
|
||||
destroy(t);
|
||||
fn := cast(proc(T1, T2, T3))t.data
|
||||
assert(t.user_index >= 3)
|
||||
arg1 := (^T1)(&t.user_args[0])^
|
||||
arg2 := (^T2)(&t.user_args[1])^
|
||||
arg3 := (^T3)(&t.user_args[2])^
|
||||
fn(arg1, arg2, arg3)
|
||||
destroy(t)
|
||||
}
|
||||
t := create(thread_proc, priority);
|
||||
t.data = rawptr(fn);
|
||||
t.user_index = 3;
|
||||
arg1, arg2, arg3 := arg1, arg2, arg3;
|
||||
mem.copy(&t.user_args[0], &arg1, size_of(arg1));
|
||||
mem.copy(&t.user_args[1], &arg2, size_of(arg2));
|
||||
mem.copy(&t.user_args[2], &arg3, size_of(arg3));
|
||||
t.init_context = init_context;
|
||||
start(t);
|
||||
t := create(thread_proc, priority)
|
||||
t.data = rawptr(fn)
|
||||
t.user_index = 3
|
||||
arg1, arg2, arg3 := arg1, arg2, arg3
|
||||
mem.copy(&t.user_args[0], &arg1, size_of(arg1))
|
||||
mem.copy(&t.user_args[1], &arg2, size_of(arg2))
|
||||
mem.copy(&t.user_args[2], &arg3, size_of(arg3))
|
||||
t.init_context = init_context
|
||||
start(t)
|
||||
}
|
||||
run_with_poly_data4 :: proc(arg1: $T1, arg2: $T2, arg3: $T3, arg4: $T4, fn: proc(arg1: T1, arg2: T2, arg3: T3, arg4: T4), init_context: Maybe(runtime.Context) = nil, priority := Thread_Priority.Normal)
|
||||
where size_of(T1) <= size_of(rawptr),
|
||||
size_of(T2) <= size_of(rawptr),
|
||||
size_of(T3) <= size_of(rawptr) {
|
||||
thread_proc :: proc(t: ^Thread) {
|
||||
fn := cast(proc(T1, T2, T3, T4))t.data;
|
||||
assert(t.user_index >= 4);
|
||||
arg1 := (^T1)(&t.user_args[0])^;
|
||||
arg2 := (^T2)(&t.user_args[1])^;
|
||||
arg3 := (^T3)(&t.user_args[2])^;
|
||||
arg4 := (^T4)(&t.user_args[3])^;
|
||||
fn(arg1, arg2, arg3, arg4);
|
||||
destroy(t);
|
||||
fn := cast(proc(T1, T2, T3, T4))t.data
|
||||
assert(t.user_index >= 4)
|
||||
arg1 := (^T1)(&t.user_args[0])^
|
||||
arg2 := (^T2)(&t.user_args[1])^
|
||||
arg3 := (^T3)(&t.user_args[2])^
|
||||
arg4 := (^T4)(&t.user_args[3])^
|
||||
fn(arg1, arg2, arg3, arg4)
|
||||
destroy(t)
|
||||
}
|
||||
t := create(thread_proc, priority);
|
||||
t.data = rawptr(fn);
|
||||
t.user_index = 4;
|
||||
arg1, arg2, arg3, arg4 := arg1, arg2, arg3, arg4;
|
||||
mem.copy(&t.user_args[0], &arg1, size_of(arg1));
|
||||
mem.copy(&t.user_args[1], &arg2, size_of(arg2));
|
||||
mem.copy(&t.user_args[2], &arg3, size_of(arg3));
|
||||
mem.copy(&t.user_args[3], &arg4, size_of(arg4));
|
||||
t.init_context = init_context;
|
||||
start(t);
|
||||
t := create(thread_proc, priority)
|
||||
t.data = rawptr(fn)
|
||||
t.user_index = 4
|
||||
arg1, arg2, arg3, arg4 := arg1, arg2, arg3, arg4
|
||||
mem.copy(&t.user_args[0], &arg1, size_of(arg1))
|
||||
mem.copy(&t.user_args[1], &arg2, size_of(arg2))
|
||||
mem.copy(&t.user_args[2], &arg3, size_of(arg3))
|
||||
mem.copy(&t.user_args[3], &arg4, size_of(arg4))
|
||||
t.init_context = init_context
|
||||
start(t)
|
||||
}
|
||||
|
||||
|
||||
|
||||
create_and_start :: proc(fn: Thread_Proc, init_context: Maybe(runtime.Context) = nil, priority := Thread_Priority.Normal) -> ^Thread {
|
||||
t := create(fn, priority);
|
||||
t.init_context = init_context;
|
||||
start(t);
|
||||
return t;
|
||||
t := create(fn, priority)
|
||||
t.init_context = init_context
|
||||
start(t)
|
||||
return t
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ Task_Status :: enum i32 {
|
||||
Term,
|
||||
}
|
||||
|
||||
Task_Proc :: #type proc(task: ^Task);
|
||||
Task_Proc :: #type proc(task: ^Task)
|
||||
|
||||
Task :: struct {
|
||||
procedure: Task_Proc,
|
||||
@@ -19,8 +19,8 @@ Task :: struct {
|
||||
user_index: int,
|
||||
}
|
||||
|
||||
Task_Id :: distinct i32;
|
||||
INVALID_TASK_ID :: Task_Id(-1);
|
||||
Task_Id :: distinct i32
|
||||
INVALID_TASK_ID :: Task_Id(-1)
|
||||
|
||||
|
||||
Pool :: struct {
|
||||
@@ -37,115 +37,115 @@ Pool :: struct {
|
||||
|
||||
pool_init :: proc(pool: ^Pool, thread_count: int, allocator := context.allocator) {
|
||||
worker_thread_internal :: proc(t: ^Thread) {
|
||||
pool := (^Pool)(t.data);
|
||||
pool := (^Pool)(t.data)
|
||||
|
||||
for pool.is_running {
|
||||
sync.semaphore_wait_for(&pool.sem_available);
|
||||
sync.semaphore_wait_for(&pool.sem_available)
|
||||
|
||||
if task, ok := pool_try_and_pop_task(pool); ok {
|
||||
pool_do_work(pool, &task);
|
||||
pool_do_work(pool, &task)
|
||||
}
|
||||
}
|
||||
|
||||
sync.semaphore_post(&pool.sem_available, 1);
|
||||
sync.semaphore_post(&pool.sem_available, 1)
|
||||
}
|
||||
|
||||
|
||||
context.allocator = allocator;
|
||||
pool.allocator = allocator;
|
||||
pool.tasks = make([dynamic]Task);
|
||||
pool.threads = make([]^Thread, thread_count);
|
||||
context.allocator = allocator
|
||||
pool.allocator = allocator
|
||||
pool.tasks = make([dynamic]Task)
|
||||
pool.threads = make([]^Thread, thread_count)
|
||||
|
||||
sync.mutex_init(&pool.mutex);
|
||||
sync.semaphore_init(&pool.sem_available);
|
||||
pool.is_running = true;
|
||||
sync.mutex_init(&pool.mutex)
|
||||
sync.semaphore_init(&pool.sem_available)
|
||||
pool.is_running = true
|
||||
|
||||
for _, i in pool.threads {
|
||||
t := create(worker_thread_internal);
|
||||
t.user_index = i;
|
||||
t.data = pool;
|
||||
pool.threads[i] = t;
|
||||
t := create(worker_thread_internal)
|
||||
t.user_index = i
|
||||
t.data = pool
|
||||
pool.threads[i] = t
|
||||
}
|
||||
}
|
||||
|
||||
pool_destroy :: proc(pool: ^Pool) {
|
||||
delete(pool.tasks);
|
||||
delete(pool.tasks)
|
||||
|
||||
for thread in &pool.threads {
|
||||
destroy(thread);
|
||||
destroy(thread)
|
||||
}
|
||||
|
||||
delete(pool.threads, pool.allocator);
|
||||
delete(pool.threads, pool.allocator)
|
||||
|
||||
sync.mutex_destroy(&pool.mutex);
|
||||
sync.semaphore_destroy(&pool.sem_available);
|
||||
sync.mutex_destroy(&pool.mutex)
|
||||
sync.semaphore_destroy(&pool.sem_available)
|
||||
}
|
||||
|
||||
pool_start :: proc(pool: ^Pool) {
|
||||
for t in pool.threads {
|
||||
start(t);
|
||||
start(t)
|
||||
}
|
||||
}
|
||||
|
||||
pool_join :: proc(pool: ^Pool) {
|
||||
pool.is_running = false;
|
||||
pool.is_running = false
|
||||
|
||||
sync.semaphore_post(&pool.sem_available, len(pool.threads));
|
||||
sync.semaphore_post(&pool.sem_available, len(pool.threads))
|
||||
|
||||
yield();
|
||||
yield()
|
||||
|
||||
for t in pool.threads {
|
||||
join(t);
|
||||
join(t)
|
||||
}
|
||||
}
|
||||
|
||||
pool_add_task :: proc(pool: ^Pool, procedure: Task_Proc, data: rawptr, user_index: int = 0) {
|
||||
sync.mutex_lock(&pool.mutex);
|
||||
defer sync.mutex_unlock(&pool.mutex);
|
||||
sync.mutex_lock(&pool.mutex)
|
||||
defer sync.mutex_unlock(&pool.mutex)
|
||||
|
||||
task: Task;
|
||||
task.procedure = procedure;
|
||||
task.data = data;
|
||||
task.user_index = user_index;
|
||||
task: Task
|
||||
task.procedure = procedure
|
||||
task.data = data
|
||||
task.user_index = user_index
|
||||
|
||||
append(&pool.tasks, task);
|
||||
sync.semaphore_post(&pool.sem_available, 1);
|
||||
append(&pool.tasks, task)
|
||||
sync.semaphore_post(&pool.sem_available, 1)
|
||||
}
|
||||
|
||||
pool_try_and_pop_task :: proc(pool: ^Pool) -> (task: Task, got_task: bool = false) {
|
||||
if sync.mutex_try_lock(&pool.mutex) {
|
||||
if len(pool.tasks) != 0 {
|
||||
intrinsics.atomic_add(&pool.processing_task_count, 1);
|
||||
task = pop_front(&pool.tasks);
|
||||
got_task = true;
|
||||
intrinsics.atomic_add(&pool.processing_task_count, 1)
|
||||
task = pop_front(&pool.tasks)
|
||||
got_task = true
|
||||
}
|
||||
sync.mutex_unlock(&pool.mutex);
|
||||
sync.mutex_unlock(&pool.mutex)
|
||||
}
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
pool_do_work :: proc(pool: ^Pool, task: ^Task) {
|
||||
task.procedure(task);
|
||||
intrinsics.atomic_sub(&pool.processing_task_count, 1);
|
||||
task.procedure(task)
|
||||
intrinsics.atomic_sub(&pool.processing_task_count, 1)
|
||||
}
|
||||
|
||||
|
||||
pool_wait_and_process :: proc(pool: ^Pool) {
|
||||
for len(pool.tasks) != 0 || intrinsics.atomic_load(&pool.processing_task_count) != 0 {
|
||||
if task, ok := pool_try_and_pop_task(pool); ok {
|
||||
pool_do_work(pool, &task);
|
||||
pool_do_work(pool, &task)
|
||||
}
|
||||
|
||||
// Safety kick
|
||||
if len(pool.tasks) != 0 && intrinsics.atomic_load(&pool.processing_task_count) == 0 {
|
||||
sync.mutex_lock(&pool.mutex);
|
||||
sync.semaphore_post(&pool.sem_available, len(pool.tasks));
|
||||
sync.mutex_unlock(&pool.mutex);
|
||||
sync.mutex_lock(&pool.mutex)
|
||||
sync.semaphore_post(&pool.sem_available, len(pool.tasks))
|
||||
sync.mutex_unlock(&pool.mutex)
|
||||
}
|
||||
|
||||
yield();
|
||||
yield()
|
||||
}
|
||||
|
||||
pool_join(pool);
|
||||
pool_join(pool)
|
||||
}
|
||||
|
||||
@@ -16,103 +16,103 @@ _thread_priority_map := [Thread_Priority]i32{
|
||||
.Normal = 0,
|
||||
.Low = -2,
|
||||
.High = +2,
|
||||
};
|
||||
}
|
||||
|
||||
_create :: proc(procedure: Thread_Proc, priority := Thread_Priority.Normal) -> ^Thread {
|
||||
win32_thread_id: win32.DWORD;
|
||||
win32_thread_id: win32.DWORD
|
||||
|
||||
__windows_thread_entry_proc :: proc "stdcall" (t_: rawptr) -> win32.DWORD {
|
||||
t := (^Thread)(t_);
|
||||
context = t.init_context.? or_else runtime.default_context();
|
||||
t := (^Thread)(t_)
|
||||
context = t.init_context.? or_else runtime.default_context()
|
||||
|
||||
t.procedure(t);
|
||||
t.procedure(t)
|
||||
|
||||
if t.init_context == nil {
|
||||
if context.temp_allocator.data == &runtime.global_default_temp_allocator_data {
|
||||
runtime.default_temp_allocator_destroy(auto_cast context.temp_allocator.data);
|
||||
runtime.default_temp_allocator_destroy(auto_cast context.temp_allocator.data)
|
||||
}
|
||||
}
|
||||
|
||||
sync.atomic_store(&t.done, true);
|
||||
return 0;
|
||||
sync.atomic_store(&t.done, true)
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
thread := new(Thread);
|
||||
thread := new(Thread)
|
||||
if thread == nil {
|
||||
return nil;
|
||||
return nil
|
||||
}
|
||||
thread.creation_allocator = context.allocator;
|
||||
thread.creation_allocator = context.allocator
|
||||
|
||||
win32_thread := win32.CreateThread(nil, 0, __windows_thread_entry_proc, thread, win32.CREATE_SUSPENDED, &win32_thread_id);
|
||||
win32_thread := win32.CreateThread(nil, 0, __windows_thread_entry_proc, thread, win32.CREATE_SUSPENDED, &win32_thread_id)
|
||||
if win32_thread == nil {
|
||||
free(thread, thread.creation_allocator);
|
||||
return nil;
|
||||
free(thread, thread.creation_allocator)
|
||||
return nil
|
||||
}
|
||||
thread.procedure = procedure;
|
||||
thread.win32_thread = win32_thread;
|
||||
thread.win32_thread_id = win32_thread_id;
|
||||
thread.init_context = context;
|
||||
thread.procedure = procedure
|
||||
thread.win32_thread = win32_thread
|
||||
thread.win32_thread_id = win32_thread_id
|
||||
thread.init_context = context
|
||||
|
||||
ok := win32.SetThreadPriority(win32_thread, _thread_priority_map[priority]);
|
||||
assert(ok == true);
|
||||
ok := win32.SetThreadPriority(win32_thread, _thread_priority_map[priority])
|
||||
assert(ok == true)
|
||||
|
||||
return thread;
|
||||
return thread
|
||||
}
|
||||
|
||||
_start :: proc(thread: ^Thread) {
|
||||
win32.ResumeThread(thread.win32_thread);
|
||||
win32.ResumeThread(thread.win32_thread)
|
||||
}
|
||||
|
||||
_is_done :: proc(using thread: ^Thread) -> bool {
|
||||
// NOTE(tetra, 2019-10-31): Apparently using wait_for_single_object and
|
||||
// checking if it didn't time out immediately, is not good enough,
|
||||
// so we do it this way instead.
|
||||
return sync.atomic_load(&done);
|
||||
return sync.atomic_load(&done)
|
||||
}
|
||||
|
||||
_join :: proc(using thread: ^Thread) {
|
||||
if win32_thread != win32.INVALID_HANDLE {
|
||||
win32.WaitForSingleObject(win32_thread, win32.INFINITE);
|
||||
win32.CloseHandle(win32_thread);
|
||||
win32_thread = win32.INVALID_HANDLE;
|
||||
win32.WaitForSingleObject(win32_thread, win32.INFINITE)
|
||||
win32.CloseHandle(win32_thread)
|
||||
win32_thread = win32.INVALID_HANDLE
|
||||
}
|
||||
}
|
||||
|
||||
_join_multiple :: proc(threads: ..^Thread) {
|
||||
MAXIMUM_WAIT_OBJECTS :: 64;
|
||||
MAXIMUM_WAIT_OBJECTS :: 64
|
||||
|
||||
handles: [MAXIMUM_WAIT_OBJECTS]win32.HANDLE;
|
||||
handles: [MAXIMUM_WAIT_OBJECTS]win32.HANDLE
|
||||
|
||||
for k := 0; k < len(threads); k += MAXIMUM_WAIT_OBJECTS {
|
||||
count := min(len(threads) - k, MAXIMUM_WAIT_OBJECTS);
|
||||
j := 0;
|
||||
count := min(len(threads) - k, MAXIMUM_WAIT_OBJECTS)
|
||||
j := 0
|
||||
for i in 0..<count {
|
||||
handle := threads[i+k].win32_thread;
|
||||
handle := threads[i+k].win32_thread
|
||||
if handle != win32.INVALID_HANDLE {
|
||||
handles[j] = handle;
|
||||
j += 1;
|
||||
handles[j] = handle
|
||||
j += 1
|
||||
}
|
||||
}
|
||||
win32.WaitForMultipleObjects(u32(j), &handles[0], true, win32.INFINITE);
|
||||
win32.WaitForMultipleObjects(u32(j), &handles[0], true, win32.INFINITE)
|
||||
}
|
||||
|
||||
for t in threads {
|
||||
win32.CloseHandle(t.win32_thread);
|
||||
t.win32_thread = win32.INVALID_HANDLE;
|
||||
win32.CloseHandle(t.win32_thread)
|
||||
t.win32_thread = win32.INVALID_HANDLE
|
||||
}
|
||||
}
|
||||
|
||||
_destroy :: proc(thread: ^Thread) {
|
||||
_join(thread);
|
||||
free(thread, thread.creation_allocator);
|
||||
_join(thread)
|
||||
free(thread, thread.creation_allocator)
|
||||
}
|
||||
|
||||
_terminate :: proc(using thread : ^Thread, exit_code: int) {
|
||||
win32.TerminateThread(win32_thread, u32(exit_code));
|
||||
win32.TerminateThread(win32_thread, u32(exit_code))
|
||||
}
|
||||
|
||||
_yield :: proc() {
|
||||
win32.SwitchToThread();
|
||||
win32.SwitchToThread()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user