diff options
author | José Bollo <jose.bollo@iot.bzh> | 2017-11-30 07:17:31 +0100 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2017-11-30 07:17:31 +0100 |
commit | b0c0093229eea9aabed1385cc9f4c5a27a7c0a87 (patch) | |
tree | 588dc8d4bd942ffc91aecf1373793535c49d490b | |
parent | 4cf8ee09b51ff41018fbdace63d71a07adf88a09 (diff) |
jobs: Fix possible race condition
Sending the signal while not being sure that is is
expected could be a race condition. Taking the mutex
avoids it.
In the same time, switch to broadcasting.
Change-Id: I3f43d0d860cccc61ec140ceef223f572f806872c
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r-- | src/jobs.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -636,7 +636,9 @@ static int on_evloop_efd(sd_event_source *s, int fd, uint32_t revents, void *use uint64_t x; struct evloop *evloop = userdata; read(evloop->efd, &x, sizeof x); - pthread_cond_signal(&evloop->cond); + pthread_mutex_lock(&mutex); + pthread_cond_broadcast(&evloop->cond); + pthread_mutex_unlock(&mutex); return 1; } @@ -656,7 +658,7 @@ struct sd_event *jobs_get_sd_event() el = &evloop[0]; if (!el->sdev) { /* creates the eventfd for waking up polls */ - el->efd = eventfd(0, EFD_CLOEXEC|EFD_SEMAPHORE); + el->efd = eventfd(0, EFD_CLOEXEC); if (el->efd < 0) { ERROR("can't make eventfd for events"); goto error1; |