Add mutexes to Murphy mainloop implementation 37/114737/1 accepted/tizen/3.0/common/20170216.151338 accepted/tizen/3.0/ivi/20170216.022714 accepted/tizen/3.0/mobile/20170216.022638 accepted/tizen/3.0/tv/20170216.022655 accepted/tizen/3.0/wearable/20170216.022707 submit/tizen_3.0/20170215.035201
authorVolodymyr Brynza <v.brynza@samsung.com>
Mon, 13 Feb 2017 12:48:05 +0000 (14:48 +0200)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 15 Feb 2017 00:57:24 +0000 (16:57 -0800)
Change-Id: Id678f6f841e21dc11abb847978e09ce5c17c7256
Signed-off-by: Volodymyr Brynza <v.brynza@samsung.com>
src/common/fragbuf.c
src/common/mainloop.c
src/common/mm.c

index 740e1384cc76284638d08c55053c8dd764f1192f..04511402e959d0cf6533143115d89030092a109b 100644 (file)
@@ -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 &&
index bf46cd877fedf45b13333cb34fa2c9cfe3e62f46..58264c16a2dd9c8b9d55e2d3514a8459c22618f0 100644 (file)
@@ -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);
 }
 
 
index b461241692f792c689e2c5505d14b1d3458d2c72..e047bf94af74a1c87b33f598e14e768ec4032e89 100644 (file)
@@ -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;
 }