diff options
author | Volodymyr Brynza <v.brynza@samsung.com> | 2017-02-13 14:48:05 +0200 |
---|---|---|
committer | Sangchul Lee <sc11.lee@samsung.com> | 2017-02-14 16:57:24 -0800 |
commit | 6b6c10334fe64dbbcf68c8c722ea74f97960e56c (patch) | |
tree | 6909c0ecac91fee97a907775f1df8ac51efac605 | |
parent | 99d4d110ceeee74e8c71025d5b09f01373d8477d (diff) | |
download | murphy-6b6c10334fe64dbbcf68c8c722ea74f97960e56c.tar.gz murphy-6b6c10334fe64dbbcf68c8c722ea74f97960e56c.tar.bz2 murphy-6b6c10334fe64dbbcf68c8c722ea74f97960e56c.zip |
Add mutexes to Murphy mainloop implementationsubmit/tizen_3.0/20170215.035201accepted/tizen/3.0/wearable/20170216.022707accepted/tizen/3.0/tv/20170216.022655accepted/tizen/3.0/mobile/20170216.022638accepted/tizen/3.0/ivi/20170216.022714accepted/tizen/3.0/common/20170216.151338
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; } |