summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2018-01-18 11:16:57 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2018-01-18 11:16:57 +0100
commitd05f95deefca2836b9f4904711a7fda1c52cd85b (patch)
tree1187555ef62bc408446f96c60439bc7b563ae36e
parentfe4d14b25cc4ca9aa10948fd014205eef4e2a3b1 (diff)
jobs: Split jobs_get_sd_event
Provide a mutex locked internal function for getting the event loop: get_sd_event_locked Change-Id: I2635f901b3ec0fcf2c52f569f4c57cfd046601af Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/jobs.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/jobs.c b/src/jobs.c
index 4b753fa1..d469c101 100644
--- a/src/jobs.c
+++ b/src/jobs.c
@@ -652,14 +652,12 @@ static int on_evloop_efd(sd_event_source *s, int fd, uint32_t revents, void *use
* Gets a sd_event item for the current thread.
* @return a sd_event or NULL in case of error
*/
-struct sd_event *jobs_get_sd_event()
+static struct sd_event *get_sd_event_locked()
{
struct evloop *el;
uint64_t x;
int rc;
- pthread_mutex_lock(&mutex);
-
/* creates the evloop on need */
el = &evloop[0];
if (!el->sdev) {
@@ -686,7 +684,6 @@ struct sd_event *jobs_get_sd_event()
error2:
close(el->efd);
error1:
- pthread_mutex_unlock(&mutex);
return NULL;
}
}
@@ -706,11 +703,25 @@ error1:
pthread_cond_wait(&el->cond, &mutex);
}
- pthread_mutex_unlock(&mutex);
return el->sdev;
}
/**
+ * Gets a sd_event item for the current thread.
+ * @return a sd_event or NULL in case of error
+ */
+struct sd_event *jobs_get_sd_event()
+{
+ struct sd_event *result;
+
+ pthread_mutex_lock(&mutex);
+ result = get_sd_event_locked();
+ pthread_mutex_unlock(&mutex);
+
+ return result;
+}
+
+/**
* Enter the jobs processing loop.
* @param allowed_count Maximum count of thread for jobs including this one
* @param start_count Count of thread to start now, must be lower.