diff --git a/glib/tests/autoptr.c b/glib/tests/autoptr.c index 076acced7..92d4bbaca 100644 --- a/glib/tests/autoptr.c +++ b/glib/tests/autoptr.c @@ -329,10 +329,30 @@ test_g_mutex (void) g_mutex_init (&val); } +/* Thread function to check that a mutex given in @data is locked */ +static gpointer +mutex_locked_thread (gpointer data) +{ + GMutex *mutex = (GMutex *) data; + g_assert_false (g_mutex_trylock (mutex)); + return NULL; +} + +/* Thread function to check that a mutex given in @data is unlocked */ +static gpointer +mutex_unlocked_thread (gpointer data) +{ + GMutex *mutex = (GMutex *) data; + g_assert_true (g_mutex_trylock (mutex)); + g_mutex_unlock (mutex); + return NULL; +} + static void test_g_mutex_locker (void) { GMutex mutex; + GThread *thread; g_mutex_init (&mutex); @@ -340,8 +360,16 @@ test_g_mutex_locker (void) { g_autoptr(GMutexLocker) val = g_mutex_locker_new (&mutex); - g_assert (val != NULL); + g_assert_nonnull (val); + + /* Verify that the mutex is actually locked */ + thread = g_thread_new ("mutex locked", mutex_locked_thread, &mutex); + g_thread_join (thread); } + + /* Verify that the mutex is unlocked again */ + thread = g_thread_new ("mutex unlocked", mutex_unlocked_thread, &mutex); + g_thread_join (thread); } /* Thread function to check that a recursive mutex given in @data is locked */