Remove g_mutex_new()/g_cond_new() in testcases

These were the last users of the dynamic allocation API.

Keep the uses in glib/tests/mutex.c since this is actually meant to test
the API (which has to continue working, even if it is deprecated).

https://bugzilla.gnome.org/show_bug.cgi?id=660739
This commit is contained in:
Ryan Lortie
2011-10-04 19:04:41 -04:00
parent 9793708931
commit 6f343ca548
10 changed files with 97 additions and 115 deletions

View File

@@ -52,24 +52,19 @@ opened_for_read (GObject *source, GAsyncResult *result, gpointer loop)
static gboolean idle_start_test1_thread (gpointer loop);
static gpointer test1_thread (gpointer user_data);
static GCond *test1_cond;
static GMutex *test1_mutex;
static gboolean test1_done;
static GCond test1_cond;
static GMutex test1_mutex;
static void
test_thread_independence (void)
{
GMainLoop *loop;
test1_cond = g_cond_new ();
test1_mutex = g_mutex_new ();
loop = g_main_loop_new (NULL, FALSE);
g_idle_add (idle_start_test1_thread, loop);
g_main_loop_run (loop);
g_main_loop_unref (loop);
g_mutex_free (test1_mutex);
g_cond_free (test1_cond);
}
static gboolean
@@ -79,16 +74,19 @@ idle_start_test1_thread (gpointer loop)
GThread *thread;
gboolean io_completed;
g_mutex_lock (test1_mutex);
g_mutex_lock (&test1_mutex);
thread = g_thread_create (test1_thread, NULL, TRUE, NULL);
g_get_current_time (&time);
time.tv_sec += 2;
io_completed = g_cond_timed_wait (test1_cond, test1_mutex, &time);
g_assert (io_completed);
while (!test1_done)
{
io_completed = g_cond_timed_wait (&test1_cond, &test1_mutex, &time);
g_assert (io_completed);
}
g_thread_join (thread);
g_mutex_unlock (test1_mutex);
g_mutex_unlock (&test1_mutex);
g_main_loop_quit (loop);
return FALSE;
}
@@ -101,8 +99,7 @@ test1_thread (gpointer user_data)
GFile *file;
/* Wait for main thread to be waiting on test1_cond */
g_mutex_lock (test1_mutex);
g_mutex_unlock (test1_mutex);
g_mutex_lock (&test1_mutex);
context = g_main_context_new ();
g_assert (g_main_context_get_thread_default () == NULL);
@@ -119,7 +116,10 @@ test1_thread (gpointer user_data)
g_main_loop_run (loop);
g_main_loop_unref (loop);
g_cond_signal (test1_cond);
test1_done = TRUE;
g_cond_signal (&test1_cond);
g_mutex_unlock (&test1_mutex);
return NULL;
}