Skip to content

Commit

Permalink
Move lock/unlock into qthread_syncvar_blocker_thread instead of havin…
Browse files Browse the repository at this point in the history
…g that be managed by the caller.
  • Loading branch information
insertinterestingnamehere committed Feb 2, 2024
1 parent bc6e935 commit ec127fe
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/syncvar.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ static aligned_t qthread_syncvar_nonblocker_thread(void *arg)
static aligned_t qthread_syncvar_blocker_thread(void *arg)
{ /*{{{ */
qthread_syncvar_blocker_t *const restrict a = (qthread_syncvar_blocker_t *)arg;

pthread_mutex_lock(&a->lock);
switch (a->type) {
case READFE: a->retval = qthread_syncvar_readFE(a->a, a->b); break;
case READFE_NB: a->retval = qthread_syncvar_readFE_nb(a->a, a->b); break;
Expand All @@ -309,6 +309,7 @@ static aligned_t qthread_syncvar_blocker_thread(void *arg)
case EMPTY: a->retval = qthread_syncvar_empty(a->a); break;
case INCR: a->retval = qthread_syncvar_incrF(a->a, *(int64_t *)a->b); break;
}
pthread_mutex_unlock(&a->lock);
return 0;
} /*}}} */

Expand All @@ -328,9 +329,7 @@ static int qthread_syncvar_blocker_func(void *dest,
{ /*{{{*/
qthread_syncvar_blocker_t args = { PTHREAD_MUTEX_INITIALIZER, dest, src, t, QTHREAD_SUCCESS };

pthread_mutex_lock(&args.lock);
qthread_fork(qthread_syncvar_blocker_thread, &args, NULL);
pthread_mutex_unlock(&args.lock);
pthread_mutex_destroy(&args.lock);
return args.retval;
} /*}}}*/
Expand Down

0 comments on commit ec127fe

Please sign in to comment.