-
Notifications
You must be signed in to change notification settings - Fork 2
Description
The current implementation of the DBus class starts a thread(worker thread) that runs a Glib main loop.
libcppconnman/src/dbus/gdbus.cpp
Lines 93 to 99 in d89262c
| glib_thread_ = std::thread([this]() { | |
| loop_ = g_main_loop_new(nullptr, FALSE); | |
| g_idle_add(&DBus::on_loop_started, this); | |
| g_main_loop_run(loop_); | |
| g_main_loop_unref(loop_); | |
| loop_ = nullptr; | |
| }); |
The purpose was to run all DBus asynchronous methods and callbacks in this thread.
The loop runs using the global-default instead of the thread-default context (more on this).
This causes the fact that if the consumer of this library creates a GMainLoop before the library loop is created on the worker thread, the callbacks are run on the thread that created the GMainLoop in the consumer.
The latter is not a problem, but it is not the purpose of the DBus class, and the worker thread is created for nothing.
It also changes where the callbacks are executed, depending on whether the consumer creates a GMainLoop or not.
Forcing to run callbacks on the worker thread should be investigated, maybe using https://docs.gtk.org/glib/method.MainContext.push_thread_default.html