summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-01-21 13:53:24 +0100
committerSven Gothel <[email protected]>2020-01-21 13:53:24 +0100
commit031145ae81daa3583ddc2bb04b7b730d48cd67c8 (patch)
tree7425742c55167c7770b91aa431e8f4e7b9b48342 /src
parentac6d3082d06183c860eea97f451d5a92022348e0 (diff)
BluetoothManager: Utilize own glib main context and associate it with the main loop
At Zafena (Issue #14), we experienced that the BluetoothGattCharacteristic callbacks '::on_properties_changed_characteristic' were not handled by BluetoothManager's own main loop thread, but passed via the 'JavaFX Main Application Thread'. BluetoothManager already utilizes its own main loop thread and it looks like it only has to register its own main context and associate it and use it as the thread local default context. This seems to be sufficient to have all other callbacks being handled from its own main loop thread.
Diffstat (limited to 'src')
-rw-r--r--src/BluetoothManager.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/BluetoothManager.cpp b/src/BluetoothManager.cpp
index 1a05776e..094dd743 100644
--- a/src/BluetoothManager.cpp
+++ b/src/BluetoothManager.cpp
@@ -99,6 +99,7 @@ public:
};
GDBusObjectManager *gdbus_manager = NULL;
+GMainContext *manager_context = NULL;
GThread *manager_thread = NULL;
std::string BluetoothManager::get_class_name() const
@@ -240,7 +241,9 @@ static gpointer init_manager_thread(void *data)
GMainLoop *loop;
GDBusObjectManager *gdbus_manager = (GDBusObjectManager *) data;
- loop = g_main_loop_new(NULL, FALSE);
+ g_main_context_push_thread_default(manager_context);
+
+ loop = g_main_loop_new(manager_context, FALSE);
g_signal_connect(gdbus_manager,
"interface-added",
@@ -252,7 +255,10 @@ static gpointer init_manager_thread(void *data)
G_CALLBACK(BluetoothEventManager::on_object_added),
NULL);
+ g_main_context_pop_thread_default(manager_context);
+
g_main_loop_run(loop);
+
return NULL;
}
@@ -261,6 +267,8 @@ BluetoothManager::BluetoothManager() : event_list()
GError *error = NULL;
GList *objects, *l;
+ manager_context = g_main_context_new ();
+ g_main_context_push_thread_default(manager_context);
gdbus_manager = object_manager_client_new_for_bus_sync(
G_BUS_TYPE_SYSTEM,
@@ -277,7 +285,9 @@ BluetoothManager::BluetoothManager() : event_list()
throw std::runtime_error(error_str);
}
- manager_thread = g_thread_new(NULL, init_manager_thread, gdbus_manager);
+ g_main_context_pop_thread_default(manager_context);
+
+ manager_thread = g_thread_new("BluetoothManager-Thread", init_manager_thread, gdbus_manager);
objects = g_dbus_object_manager_get_objects(gdbus_manager);