diff options
author | Volodymyr Brynza <v.brynza@samsung.com> | 2017-02-13 14:48:05 +0200 |
---|---|---|
committer | Volodymyr Brynza <v.brynza@samsung.com> | 2017-02-13 14:48:05 +0200 |
commit | fb3a463b2109c33f1dfe41a1e680a3557354ff52 (patch) | |
tree | 747489ed49f8683d4d94540720106a6bdb1bb1ef | |
parent | 4d6f69e0916e83854da7f548cb21bad777cf27bc (diff) | |
download | murphy-fb3a463b2109c33f1dfe41a1e680a3557354ff52.tar.gz murphy-fb3a463b2109c33f1dfe41a1e680a3557354ff52.tar.bz2 murphy-fb3a463b2109c33f1dfe41a1e680a3557354ff52.zip |
Add mutexes to Murphy mainloop implementation
Change-Id: Id678f6f841e21dc11abb847978e09ce5c17c7256
Signed-off-by: Volodymyr Brynza <v.brynza@samsung.com>
-rw-r--r-- | src/common/fragbuf.c | 4 | ||||
-rw-r--r-- | src/common/mainloop.c | 16 | ||||
-rw-r--r-- | src/common/mm.c | 16 |
3 files changed, 33 insertions, 3 deletions
diff --git a/src/common/fragbuf.c b/src/common/fragbuf.c index 740e138..0451140 100644 --- a/src/common/fragbuf.c +++ b/src/common/fragbuf.c @@ -189,7 +189,9 @@ int mrp_fragbuf_pull(mrp_fragbuf_t *buf, void **datap, size_t *sizep) void *data; uint32_t size; - if (buf == NULL || buf->used <= 0) + if (buf == NULL) + return FALSE; + if (buf->used <= 0) return FALSE; if (MRP_UNLIKELY(*datap && 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); } diff --git a/src/common/mm.c b/src/common/mm.c index b461241..e047bf9 100644 --- a/src/common/mm.c +++ b/src/common/mm.c @@ -30,6 +30,7 @@ #include <stdio.h> #include <stdlib.h> #include <stdint.h> +#include <mcheck.h> #include <errno.h> #include <unistd.h> #include <execinfo.h> @@ -522,6 +523,10 @@ static int __passthru_memalign(void **ptr, size_t align, size_t size, return posix_memalign(ptr, align, size); } +MRP_INIT static void menory_check_init() +{ + mcheck(NULL); +} static void __passthru_free(void *ptr, const char *file, int line, const char *func) @@ -529,8 +534,14 @@ static void __passthru_free(void *ptr, const char *file, int line, MRP_UNUSED(file); MRP_UNUSED(line); MRP_UNUSED(func); + if (ptr == NULL) + return; - free(ptr); + if (mprobe(ptr) == MCHECK_OK) + free(ptr); + else { + mrp_log_error("Invalid pointer passed to fuction free"); + } } @@ -579,7 +590,8 @@ int mrp_mm_memalign(void **ptr, size_t align, size_t size, const char *file, void mrp_mm_free(void *ptr, const char *file, int line, const char *func) { - return __mm.free(ptr, file, line, func); + __mm.free(ptr, file, line, func); + return; } |