mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-05 18:40:58 +01:00
tests: Update GMutexLocker tests
Spawn a thread and assert that the mutex actually got locked and then unlocked again, same as we do in GRecMutexLocker tests.
This commit is contained in:
parent
8c2e71bba0
commit
e7e40ba1cf
@ -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 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user