diff options
author | Ingo Huerner <ingo.huerner@xse.de> | 2015-01-14 12:58:20 +0100 |
---|---|---|
committer | Ingo Huerner <ingo.huerner@xse.de> | 2015-01-14 12:58:20 +0100 |
commit | 2146c331f4bf8396c1b62d9160df61f1894e23b6 (patch) | |
tree | 6339024d22f32d58b26ed2bd09dd2288850b1895 | |
parent | 69ea94b69ca160e6f92a1abf99ff0a5397c3c998 (diff) | |
download | persistence-client-library-2146c331f4bf8396c1b62d9160df61f1894e23b6.tar.gz |
Fixed GENIVI code review issues 3
-rw-r--r-- | src/persistence_client_library_dbus_service.c | 18 | ||||
-rw-r--r-- | src/persistence_client_library_dbus_service.h | 4 |
2 files changed, 18 insertions, 4 deletions
diff --git a/src/persistence_client_library_dbus_service.c b/src/persistence_client_library_dbus_service.c index 0f1d801..126965c 100644 --- a/src/persistence_client_library_dbus_service.c +++ b/src/persistence_client_library_dbus_service.c @@ -44,6 +44,8 @@ pthread_cond_t gMainLoopCond = PTHREAD_COND_INITIALIZER; pthread_t gMainLoopThread; +volatile int gMainLoopCondValue = 0; +volatile int gInitCondValue = 0; const char* gDbusLcConsDest = "org.genivi.NodeStateManager"; @@ -334,8 +336,10 @@ int setup_dbus_mainloop(void) (void)pthread_setname_np(gMainLoopThread, "pclDbusLoop"); // wait for condition variable - pthread_cond_wait(&gDbusInitializedCond, &gDbusInitializedMtx); + while(0 == gInitCondValue) + pthread_cond_wait(&gDbusInitializedCond, &gDbusInitializedMtx); + gInitCondValue = 0; pthread_mutex_unlock(&gDbusInitializedMtx); return rval; @@ -527,7 +531,7 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2, else if (NULL != conn) { dbus_connection_set_exit_on_disconnect(conn, FALSE); - //if (-1 == (gEfds = eventfd(0, 0))) + if (-1 == (pipe(gPipeFd))) { DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop - eventfd() failed w/ errno:"), DLT_INT(errno) ); @@ -558,6 +562,7 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2, } else { + gInitCondValue = 1; pthread_cond_signal(&gDbusInitializedCond); pthread_mutex_unlock(&gDbusInitializedMtx); do @@ -655,6 +660,8 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2, DLT_LOG(gPclDLTContext, DLT_LOG_ERROR, DLT_STRING("mainLoop - cmd not handled"), DLT_INT(readData.message.cmd) ); break; } + + gMainLoopCondValue = 1; pthread_cond_signal(&gMainLoopCond); pthread_mutex_unlock(&gMainCondMtx); } @@ -703,6 +710,7 @@ int mainLoop(DBusObjectPathVTable vtable, DBusObjectPathVTable vtable2, dbus_shutdown(); } + //gInitCondValue = 0; pthread_cond_signal(&gDbusInitializedCond); pthread_mutex_unlock(&gDbusInitializedMtx); return 0; @@ -720,9 +728,11 @@ int deliverToMainloop(MainLoopData_u* payload) deliverToMainloop_NM(payload); - pthread_cond_wait(&gMainLoopCond, &gMainCondMtx); - pthread_mutex_unlock(&gMainCondMtx); + while(0 == gMainLoopCondValue) + pthread_cond_wait(&gMainLoopCond, &gMainCondMtx); + gMainLoopCondValue = 0; + pthread_mutex_unlock(&gMainCondMtx); pthread_mutex_unlock(&gDeliverpMtx); diff --git a/src/persistence_client_library_dbus_service.h b/src/persistence_client_library_dbus_service.h index 3bebf57..f9154c4 100644 --- a/src/persistence_client_library_dbus_service.h +++ b/src/persistence_client_library_dbus_service.h @@ -78,6 +78,10 @@ extern pthread_mutex_t gMainCondMtx __attribute__ ((visibility ("hidden"))); /// dbus mainloop mutex => visibility "hidden" to prevent the use outside the library extern pthread_t gMainLoopThread; +extern volatile int gMainLoopCondValue __attribute__ ((visibility ("hidden"))); + +extern volatile int gInitCondValue __attribute__ ((visibility ("hidden"))); + /// lifecycle consumer interface dbus name extern const char* gDbusLcConsterface; /// lifecycle consumer dbus interface |