summaryrefslogtreecommitdiffstats
path: root/src/server/threadpool.c
diff options
context:
space:
mode:
authorSimon Rettberg2020-03-14 17:27:13 +0100
committerSimon Rettberg2020-03-14 17:27:13 +0100
commitd3df3ba3005977629b8847b507df1fdae40ffbd5 (patch)
treeddbe9a666b82ed471428d841d3f2afd566281861 /src/server/threadpool.c
parent[SERVER] Remove uplink_ prefix from static (private) functions (diff)
downloaddnbd3-d3df3ba3005977629b8847b507df1fdae40ffbd5.tar.gz
dnbd3-d3df3ba3005977629b8847b507df1fdae40ffbd5.tar.xz
dnbd3-d3df3ba3005977629b8847b507df1fdae40ffbd5.zip
[SERVER] threadpool: Simplify get code, make debug code _DEBUG only
Diffstat (limited to 'src/server/threadpool.c')
-rw-r--r--src/server/threadpool.c11
1 files changed, 7 insertions, 4 deletions
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