Browse Source

Combine join and destroy for threads

gingerBill 2 years ago
parent
commit
134c7db4d2
2 changed files with 4 additions and 15 deletions
  1. 2 7
      src/thread_pool.cpp
  2. 2 8
      src/threading.cpp

+ 2 - 7
src/thread_pool.cpp

@@ -57,14 +57,9 @@ gb_internal void thread_pool_destroy(ThreadPool *pool) {
 
 	for_array(i, pool->threads) {
 		Thread *t = &pool->threads[i];
-		thread_join(t);
+		thread_join_and_destroy(t);
 	}
-	
-	for_array(i, pool->threads) {
-		Thread *t = &pool->threads[i];
-		thread_destroy(t);
-	}
-	
+
 	gb_free(pool->allocator, pool->threads.data);
 	mutex_destroy(&pool->mutex);
 	condition_destroy(&pool->task_cond);

+ 2 - 8
src/threading.cpp

@@ -61,8 +61,7 @@ gb_internal u32  thread_current_id(void);
 
 gb_internal void thread_init_and_start           (Thread *t, ThreadProc *proc, void *data);
 gb_internal void thread_init_and_start_with_stack(Thread *t, ThreadProc *proc, void *data, isize stack_size);
-gb_internal void thread_destroy         (Thread *t);
-gb_internal void thread_join            (Thread *t);
+gb_internal void thread_join_and_destroy(Thread *t);
 gb_internal bool thread_is_running      (Thread const *t);
 gb_internal void thread_set_name        (Thread *t, char const *name);
 
@@ -326,11 +325,6 @@ gb_internal gb_inline void yield(void) {
 #endif
 }
 
-gb_internal void thread_destroy(Thread *t) {
-	thread_join(t);
-}
-
-
 gb_internal void private__thread_run(Thread *t) {
 	t->return_value = t->proc(t);
 }
@@ -390,7 +384,7 @@ gb_internal void thread_init_and_start_with_stack(Thread *t, ThreadProc *proc, v
 #endif
 }
 
-gb_internal void thread_join(Thread *t) {
+gb_internal void thread_join_and_destroy(Thread *t) {
 	if (!t->is_running.load()) {
 		return;
 	}