From d3df3ba3005977629b8847b507df1fdae40ffbd5 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Sat, 14 Mar 2020 17:27:13 +0100 Subject: [SERVER] threadpool: Simplify get code, make debug code _DEBUG only --- src/server/threadpool.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/server/threadpool.c') diff --git a/src/server/threadpool.c b/src/server/threadpool.c index 0b46fd6..96162a6 100644 --- a/src/server/threadpool.c +++ b/src/server/threadpool.c @@ -62,15 +62,16 @@ bool threadpool_run(void *(*startRoutine)(void *), void *arg) logadd( LOG_MINOR, "Cannot submit work to threadpool while shutting down!" ); return false; } +#ifdef _DEBUG if ( unlikely( startRoutine == NULL ) ) { logadd( LOG_ERROR, "Trying to queue work for thread pool with NULL startRoutine" ); return false; // Or bail out!? } - entry_t *entry = NULL; +#endif + entry_t *entry; for ( int i = 0; i < maxIdleThreads; ++i ) { - entry_t *cur = pool[i]; - if ( cur != NULL && atomic_compare_exchange_weak( &pool[i], &cur, NULL ) ) { - entry = cur; + entry = atomic_exchange( &pool[i], NULL ); + if ( entry != NULL ) { break; } } @@ -120,10 +121,12 @@ keep_going:; logadd( LOG_DEBUG1, "Unexpected return value %d for signal_wait in threadpool worker!", ret ); continue; } +#ifdef _DEBUG if ( entry->startRoutine == NULL ) { logadd( LOG_ERROR, "Worker woke up but has no work to do!" ); exit( 1 ); } +#endif // Start assigned work (*entry->startRoutine)( entry->arg ); // Reset vars for safety -- cgit v1.2.3-55-g7522