summaryrefslogtreecommitdiff
path: root/src/common/mainloop.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/mainloop.c')
-rw-r--r--src/common/mainloop.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/common/mainloop.c b/src/common/mainloop.c
index bf46cd8..58264c1 100644
--- a/src/common/mainloop.c
+++ b/src/common/mainloop.c
@@ -36,6 +36,7 @@
#include <sys/epoll.h>
#include <sys/signalfd.h>
#include <sys/socket.h>
+#include <pthread.h>
#include <murphy/common/macros.h>
#include <murphy/common/mm.h>
@@ -293,6 +294,8 @@ struct mrp_mainloop_s {
mrp_list_hook_t busses; /* known event busses */
mrp_list_hook_t eventq; /* pending events */
mrp_deferred_t *eventd; /* deferred event pump cb */
+
+ pthread_mutex_t lock;
};
@@ -1266,6 +1269,8 @@ static void super_work_cb(void *super_data, void *id, void *user_data)
MRP_UNUSED(super_data);
MRP_UNUSED(id);
+ pthread_mutex_lock(&ml->lock);
+
mrp_mainloop_poll(ml, FALSE);
mrp_mainloop_dispatch(ml);
@@ -1306,6 +1311,8 @@ static void super_work_cb(void *super_data, void *id, void *user_data)
ml->timer = NULL;
}
}
+
+ pthread_mutex_unlock(&ml->lock);
}
@@ -1563,6 +1570,8 @@ mrp_mainloop_t *mrp_mainloop_create(void)
if (!setup_sighandlers(ml))
goto fail;
+
+ pthread_mutex_init(&ml->lock, NULL);
}
else {
fail:
@@ -1582,6 +1591,7 @@ mrp_mainloop_t *mrp_mainloop_create(void)
void mrp_mainloop_destroy(mrp_mainloop_t *ml)
{
if (ml != NULL) {
+ pthread_mutex_lock(&ml->lock);
mrp_clear_superloop(ml);
purge_io_watches(ml);
purge_timers(ml);
@@ -1596,6 +1606,8 @@ void mrp_mainloop_destroy(mrp_mainloop_t *ml)
fdtbl_destroy(ml->fdtbl);
mrp_free(ml->events);
+ pthread_mutex_unlock(&ml->lock);
+ pthread_mutex_destroy(&ml->lock);
mrp_free(ml);
}
}
@@ -2230,8 +2242,12 @@ int mrp_mainloop_run(mrp_mainloop_t *ml)
void mrp_mainloop_quit(mrp_mainloop_t *ml, int exit_code)
{
+ pthread_mutex_lock(&ml->lock);
+
ml->exit_code = exit_code;
ml->quit = TRUE;
+
+ pthread_mutex_unlock(&ml->lock);
}