mirror of
				https://gitlab.gnome.org/GNOME/glib.git
				synced 2025-10-31 00:12:19 +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:
		| @@ -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 */ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user