Remove unneeded semicolons from the core library

This commit is contained in:
gingerBill
2021-08-31 22:21:13 +01:00
parent b176af2742
commit 251da264ed
187 changed files with 27227 additions and 27227 deletions
+49 -49
View File
@@ -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)
}