1 #undef G_DISABLE_ASSERT
3 #define G_ERRORCHECK_MUTEXES
10 locking_thread (gpointer mutex
)
12 g_mutex_lock ((GMutex
*)mutex
);
18 lock_locked_mutex (void)
20 GMutex
* mutex
= g_mutex_new ();
26 trylock_locked_mutex (void)
28 GMutex
* mutex
= g_mutex_new ();
30 g_mutex_trylock (mutex
);
34 unlock_unlocked_mutex (void)
36 GMutex
* mutex
= g_mutex_new ();
38 g_mutex_unlock (mutex
);
39 g_mutex_unlock (mutex
);
43 free_locked_mutex (void)
45 GMutex
* mutex
= g_mutex_new ();
51 wait_on_unlocked_mutex (void)
53 GMutex
* mutex
= g_mutex_new ();
54 GCond
* cond
= g_cond_new ();
55 g_cond_wait (cond
, mutex
);
59 wait_on_otherwise_locked_mutex (void)
61 GMutex
* mutex
= g_mutex_new ();
62 GCond
* cond
= g_cond_new ();
63 GThread
* thread
= g_thread_create (locking_thread
, mutex
, TRUE
, NULL
);
64 g_assert (thread
!= NULL
);
65 g_usleep (G_USEC_PER_SEC
);
66 g_cond_wait (cond
, mutex
);
70 timed_wait_on_unlocked_mutex (void)
72 GMutex
* mutex
= g_mutex_new ();
73 GCond
* cond
= g_cond_new ();
74 g_cond_timed_wait (cond
, mutex
, NULL
);
78 timed_wait_on_otherwise_locked_mutex (void)
80 GMutex
* mutex
= g_mutex_new ();
81 GCond
* cond
= g_cond_new ();
82 GThread
* thread
= g_thread_create (locking_thread
, mutex
, TRUE
, NULL
);
83 g_assert (thread
!= NULL
);
84 g_usleep (G_USEC_PER_SEC
);
85 g_cond_timed_wait (cond
, mutex
, NULL
);
94 {"lock_locked_mutex", lock_locked_mutex
},
95 {"trylock_locked_mutex", trylock_locked_mutex
},
96 {"unlock_unlocked_mutex", unlock_unlocked_mutex
},
97 {"free_locked_mutex", free_locked_mutex
},
98 {"wait_on_unlocked_mutex", wait_on_unlocked_mutex
},
99 {"wait_on_otherwise_locked_mutex", wait_on_otherwise_locked_mutex
},
100 {"timed_wait_on_unlocked_mutex", timed_wait_on_unlocked_mutex
},
101 {"timed_wait_on_otherwise_locked_mutex",
102 timed_wait_on_otherwise_locked_mutex
}
106 main (int argc
, char* argv
[])
112 for (i
= 0; i
< G_N_ELEMENTS (func_table
); i
++)
114 if (strcmp (func_table
[i
].name
, argv
[1]) == 0)
116 g_thread_init (NULL
);
117 func_table
[i
].func ();
118 g_assert_not_reached ();
123 fprintf (stderr
, "Usage: errorcheck-mutex-test [TEST]\n\n");
124 fprintf (stderr
, " where TEST can be one of:\n\n");
125 for (i
= 0; i
< G_N_ELEMENTS (func_table
); i
++)
127 fprintf (stderr
, " %s\n", func_table
[i
].name
);