Skip to content

Commit

Permalink
Use a condition variable for manking an external wait on a FEB call.
Browse files Browse the repository at this point in the history
  • Loading branch information
insertinterestingnamehere committed Feb 9, 2024
1 parent 4cdfe8c commit e401489
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/feb.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ typedef enum bt {
} blocker_type;
typedef struct {
pthread_mutex_t lock;
pthread_cond_t condition;
void *a;
void *b;
blocker_type type;
Expand Down Expand Up @@ -230,20 +231,23 @@ static aligned_t qthread_feb_blocker_thread(void *arg)
a->retval = qthread_empty(a->a);
break;
}
pthread_mutex_unlock(&(a->lock));
pthread_mutex_lock(&a->lock);
pthread_cond_signal(&a->condition);
pthread_mutex_unlock(&a->lock);
return 0;
} /*}}} */

static int qthread_feb_blocker_func(void *dest,
void *src,
blocker_type t)
{ /*{{{*/
qthread_feb_blocker_t args = { PTHREAD_MUTEX_INITIALIZER, dest, src, t, QTHREAD_SUCCESS };
qthread_feb_blocker_t args = { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, dest, src, t, QTHREAD_SUCCESS };

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

0 comments on commit e401489

Please sign in to comment.