mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-09-27 17:52:58 +02:00
action exporter: clarify threading situation
Exporting can only be done relative to a particular given main context and all interaction with the action group must be on that same context. Fix up the implementation so that the user can specify that context with the normal (thread default) mechanism and document the limitation on the API. Adjust the testcase to adhere to the documentation limitations. It passes now.
This commit is contained in:
@@ -624,33 +624,22 @@ test_dbus_export (void)
|
||||
g_object_unref (bus);
|
||||
}
|
||||
|
||||
static gpointer
|
||||
do_activate (gpointer data)
|
||||
{
|
||||
GSimpleActionGroup *group = data;
|
||||
gint i;
|
||||
GAction *action;
|
||||
|
||||
for (i = 0; i < 1000000; i++)
|
||||
{
|
||||
action = g_simple_action_group_lookup (group, "a");
|
||||
g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
|
||||
!g_action_get_enabled (action));
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gpointer
|
||||
do_export (gpointer data)
|
||||
{
|
||||
GActionGroup *group = data;
|
||||
GMainContext *ctx;
|
||||
gint i;
|
||||
GError *error = NULL;
|
||||
guint id;
|
||||
GDBusConnection *bus;
|
||||
GAction *action;
|
||||
gchar *path;
|
||||
|
||||
ctx = g_main_context_new ();
|
||||
|
||||
g_main_context_push_thread_default (ctx);
|
||||
|
||||
bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
|
||||
path = g_strdup_printf("/%p", data);
|
||||
|
||||
@@ -658,12 +647,23 @@ do_export (gpointer data)
|
||||
{
|
||||
id = g_dbus_connection_export_action_group (bus, path, G_ACTION_GROUP (group), &error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
action = g_simple_action_group_lookup (G_SIMPLE_ACTION_GROUP (group), "a");
|
||||
g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
|
||||
!g_action_get_enabled (action));
|
||||
|
||||
g_dbus_connection_unexport_action_group (bus, id);
|
||||
|
||||
while (g_main_context_iteration (ctx, FALSE));
|
||||
}
|
||||
|
||||
g_free (path);
|
||||
g_object_unref (bus);
|
||||
|
||||
g_main_context_pop_thread_default (ctx);
|
||||
|
||||
g_main_context_unref (ctx);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -671,7 +671,6 @@ static void
|
||||
test_dbus_threaded (void)
|
||||
{
|
||||
GSimpleActionGroup *group[10];
|
||||
GThread *call[10];
|
||||
GThread *export[10];
|
||||
static GActionEntry entries[] = {
|
||||
{ "a", activate_action, NULL, NULL, NULL },
|
||||
@@ -683,15 +682,11 @@ test_dbus_threaded (void)
|
||||
{
|
||||
group[i] = g_simple_action_group_new ();
|
||||
g_simple_action_group_add_entries (group[i], entries, G_N_ELEMENTS (entries), NULL);
|
||||
call[i] = g_thread_new ("call", do_activate, group[i]);
|
||||
export[i] = g_thread_new ("export", do_export, group[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < 10; i++)
|
||||
{
|
||||
g_thread_join (call[i]);
|
||||
g_thread_join (export[i]);
|
||||
}
|
||||
g_thread_join (export[i]);
|
||||
|
||||
for (i = 0; i < 10; i++)
|
||||
g_object_unref (group[i]);
|
||||
|
Reference in New Issue
Block a user