aboutsummaryrefslogtreecommitdiff
path: root/src/pthreads.c
diff options
context:
space:
mode:
authorMarat Dukhan <maratek@gmail.com>2020-04-10 17:16:42 -0700
committerMarat Dukhan <maratek@gmail.com>2020-04-10 17:16:42 -0700
commitddd479bcd8ba87094132ecf438dd76eb08ee3b0d (patch)
treeb10c6742fbc0ea3c83ac014971159360b3933c40 /src/pthreads.c
parentfa7261344568f86760231591a7158519fd43f382 (diff)
downloadpthreadpool-ddd479bcd8ba87094132ecf438dd76eb08ee3b0d.tar.gz
Replace atomic fetch_sub with decrement_fetch primitive
Decrement-fetch is a closer match to the primitive used in implementation
Diffstat (limited to 'src/pthreads.c')
-rw-r--r--src/pthreads.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/pthreads.c b/src/pthreads.c
index e70ab18..a7e4619 100644
--- a/src/pthreads.c
+++ b/src/pthreads.c
@@ -79,13 +79,13 @@
static void checkin_worker_thread(struct pthreadpool* threadpool) {
#if PTHREADPOOL_USE_FUTEX
- if (pthreadpool_fetch_sub_relaxed_size_t(&threadpool->active_threads, 1) == 1) {
+ if (pthreadpool_decrement_fetch_relaxed_size_t(&threadpool->active_threads) == 0) {
pthreadpool_store_relaxed_uint32_t(&threadpool->has_active_threads, 0);
futex_wake_all(&threadpool->has_active_threads);
}
#else
pthread_mutex_lock(&threadpool->completion_mutex);
- if (pthreadpool_fetch_sub_relaxed_size_t(&threadpool->active_threads, 1) == 1) {
+ if (pthreadpool_decrement_fetch_relaxed_size_t(&threadpool->active_threads) == 0) {
pthread_cond_signal(&threadpool->completion_condvar);
}
pthread_mutex_unlock(&threadpool->completion_mutex);