Add a build flag for switching to single-threading mode 19/114019/2
authorMu-Woong Lee <muwoong.lee@samsung.com>
Thu, 9 Feb 2017 13:56:02 +0000 (22:56 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Fri, 10 Feb 2017 04:08:55 +0000 (13:08 +0900)
Change-Id: I306967d85eeb792a375c877cf48dcfa1ebc06f42
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
src/server/DBusService.cpp

index c02dec3..052498d 100644 (file)
@@ -42,6 +42,7 @@ DBusService::DBusService(GDBusConnection* conn, const char* serviceName, const c
 
 DBusService::~DBusService()
 {
+#ifndef SINGLE_THREADING
        if (__mainLoop && g_main_loop_is_running(__mainLoop)) {
                _I(PURPLE("Stopping the mainloop of '%s'"), __serviceName);
                g_main_loop_quit(__mainLoop);
@@ -51,6 +52,9 @@ DBusService::~DBusService()
                _I("Joining the thread of '%s'", __serviceName);
                g_thread_join(__gthread);
        }
+#else
+       __release();
+#endif
 }
 
 GDBusConnection* DBusService::getConnection()
@@ -62,8 +66,15 @@ bool DBusService::start()
 {
        _I("Preparing '%s'", __serviceName);
 
+#ifndef SINGLE_THREADING
        __gthread = g_thread_new(__serviceName, __threadFunc, this);
        IF_FAIL_RETURN_TAG(__gthread, false, _E, "Thread creation failed");
+#else
+       _I(CYAN("'%s' runs on the default main loop"), __serviceName);
+       IF_FAIL_RETURN(__init(), false);
+       prepare();
+#endif
+
        return true;
 }
 
@@ -124,6 +135,7 @@ bool DBusService::__init()
        vtable.get_property = NULL;
        vtable.set_property = NULL;
 
+#ifndef SINGLE_THREADING
        __mainContext = g_main_context_new();
        IF_FAIL_RETURN_TAG(__mainContext, false, _E, "MainContext creation failed");
 
@@ -131,6 +143,7 @@ bool DBusService::__init()
 
        __mainLoop = g_main_loop_new(__mainContext, FALSE);
        IF_FAIL_RETURN_TAG(__mainLoop, false, _E, "MainLoop creation failed");
+#endif
 
        std::string introspection("<node><interface name='");
        introspection += __interface + "'>" + __methodSpecs + "</interface></node>";
@@ -168,11 +181,13 @@ void DBusService::__release()
        if (__nodeInfo)
                g_dbus_node_info_unref(__nodeInfo);
 
+#ifndef SINGLE_THREADING
        if (__mainLoop)
                g_main_loop_unref(__mainLoop);
 
        if (__mainContext)
                g_main_context_unref(__mainContext);
+#endif
 }
 
 void DBusService::__onUserNew(GDBusConnection* conn, const gchar* sender,