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>
* Gets a sd_event item for the current thread.
* @return a sd_event or NULL in case of error
*/
* 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;
{
struct evloop *el;
uint64_t x;
int rc;
- pthread_mutex_lock(&mutex);
-
/* creates the evloop on need */
el = &evloop[0];
if (!el->sdev) {
/* creates the evloop on need */
el = &evloop[0];
if (!el->sdev) {
error2:
close(el->efd);
error1:
error2:
close(el->efd);
error1:
- pthread_mutex_unlock(&mutex);
pthread_cond_wait(&el->cond, &mutex);
}
pthread_cond_wait(&el->cond, &mutex);
}
- pthread_mutex_unlock(&mutex);
+/**
+ * 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
/**
* Enter the jobs processing loop.
* @param allowed_count Maximum count of thread for jobs including this one