[glib] gio/tests/tls-interaction: fix two sporadic errors



commit 15f1ba47219be9cf92b1a6a1b615c090afde836d
Author: Dan Winship <danw gnome org>
Date:   Sun Sep 4 10:33:37 2011 -0400

    gio/tests/tls-interaction: fix two sporadic errors
    
    The threaded tests are using the default main context in the worker
    thread, but were not g_main_context_acquire()ing it first, which meant
    that g_tls_interaction_invoke_ask_password() in the main thread would
    sometimes succeed in acquiring it itself and thus performing the
    operation in the wrong thread. Fix that.
    
    Also, we can't unref the loop from the worker thread, because the main
    thread isn't holding a reference on it, and so it might end up being
    destroyed while that thread is still inside g_main_loop_quit().

 gio/tests/tls-interaction.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
---
diff --git a/gio/tests/tls-interaction.c b/gio/tests/tls-interaction.c
index 242a92e..45b613c 100644
--- a/gio/tests/tls-interaction.c
+++ b/gio/tests/tls-interaction.c
@@ -409,14 +409,14 @@ thread_loop (gpointer user_data)
   g_assert (test->loop == NULL);
   test->loop = g_main_loop_new (context, TRUE);
 
+  g_main_context_acquire (context);
   g_cond_signal (closure->loop_started);
   g_mutex_unlock (closure->loop_mutex);
 
   while (g_main_loop_is_running (test->loop))
     g_main_context_iteration (context, TRUE);
 
-  g_main_loop_unref (test->loop);
-  test->loop = NULL;
+  g_main_context_release (context);
   return test;
 }
 
@@ -459,7 +459,7 @@ teardown_with_thread_loop (Test            *test,
   g_assert (check == test);
   test->loop_thread = NULL;
 
-  g_assert (test->loop == NULL);
+  g_main_loop_unref (test->loop);
 
   teardown_without_loop (test, unused);
 }



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