[glib] ContextSpecificGroup: some fixups



commit 0de16c98f7606da0d6cb3700bb6eeac0e16ac4a4
Author: Ryan Lortie <desrt desrt ca>
Date:   Fri Mar 13 17:34:57 2015 -0400

    ContextSpecificGroup: some fixups
    
    For all of the effort spent ensuring that this algorithm would be
    correctly threadsafe, I messed up the order of operations within a
    single thread when porting to the new approach.
    
    Fix that up.
    
    Also: fix some overzealous asserting in the testcases.  Since shutdown
    is now lazy, we can never surely say !is_running at any particular point
    in time.

 gio/gcontextspecificgroup.c |    7 +++----
 gio/tests/contexts.c        |    5 ++---
 2 files changed, 5 insertions(+), 7 deletions(-)
---
diff --git a/gio/gcontextspecificgroup.c b/gio/gcontextspecificgroup.c
index 47a49c4..b0eb279 100644
--- a/gio/gcontextspecificgroup.c
+++ b/gio/gcontextspecificgroup.c
@@ -182,10 +182,6 @@ g_context_specific_group_get (GContextSpecificGroup *group,
   if (!group->table)
     group->table = g_hash_table_new (NULL, NULL);
 
-  /* start only if there are no others */
-  if (start_func && g_hash_table_size (group->table) == 0)
-    g_context_specific_group_request_state (group, TRUE, start_func);
-
   css = g_hash_table_lookup (group->table, context);
 
   if (!css)
@@ -202,6 +198,9 @@ g_context_specific_group_get (GContextSpecificGroup *group,
   else
     g_object_ref (css->instance);
 
+  if (start_func)
+    g_context_specific_group_request_state (group, TRUE, start_func);
+
   g_mutex_unlock (&group->lock);
 
   return css->instance;
diff --git a/gio/tests/contexts.c b/gio/tests/contexts.c
index 6d7412a..4bed037 100644
--- a/gio/tests/contexts.c
+++ b/gio/tests/contexts.c
@@ -313,7 +313,7 @@ test_context_specific_identity (void)
   for (i = 0; i < N_THREADS; i++)
     exited |= GPOINTER_TO_UINT (g_thread_join (threads[i]));
   g_assert (exited);
-  g_assert (!g_atomic_int_get (&is_running));
+  g_assert (!group.requested_state);
 }
 
 static void
@@ -362,7 +362,6 @@ test_context_specific_emit (void)
   gboolean exited = FALSE;
   guint i, n;
 
-  g_assert (!g_atomic_int_get (&is_running));
   for (i = 0; i < N_THREADS; i++)
     threads[i] = g_thread_new ("test", test_emit_thread, &observed_values[i]);
 
@@ -397,7 +396,7 @@ test_context_specific_emit (void)
   for (i = 0; i < N_THREADS; i++)
     exited |= GPOINTER_TO_UINT (g_thread_join (threads[i]));
   g_assert (exited);
-  g_assert (!g_atomic_int_get (&is_running));
+  g_assert (!group.requested_state);
 }
 
 int


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]