mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-26 05:56:14 +01:00
mainloop test: use atomic for cross-thread access
This commit is contained in:
parent
42c2c4f67d
commit
46b15bb581
@ -762,14 +762,14 @@ test_mainloop_overflow (void)
|
|||||||
g_main_context_unref (ctx);
|
g_main_context_unref (ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static volatile gboolean ready_time_dispatched;
|
static volatile gint ready_time_dispatched;
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
ready_time_dispatch (GSource *source,
|
ready_time_dispatch (GSource *source,
|
||||||
GSourceFunc callback,
|
GSourceFunc callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
ready_time_dispatched = TRUE;
|
g_atomic_int_set (&ready_time_dispatched, TRUE);
|
||||||
|
|
||||||
g_source_set_ready_time (source, -1);
|
g_source_set_ready_time (source, -1);
|
||||||
|
|
||||||
@ -862,13 +862,13 @@ test_ready_time (void)
|
|||||||
g_source_set_ready_time (source, 0);
|
g_source_set_ready_time (source, 0);
|
||||||
loop = g_main_loop_new (NULL, FALSE);
|
loop = g_main_loop_new (NULL, FALSE);
|
||||||
thread = g_thread_new ("context thread", run_context, loop);
|
thread = g_thread_new ("context thread", run_context, loop);
|
||||||
while (!ready_time_dispatched);
|
while (!g_atomic_int_get (&ready_time_dispatched));
|
||||||
|
|
||||||
/* Now let's see if it can wake up from sleeping. */
|
/* Now let's see if it can wake up from sleeping. */
|
||||||
g_usleep (G_TIME_SPAN_SECOND / 2);
|
g_usleep (G_TIME_SPAN_SECOND / 2);
|
||||||
ready_time_dispatched = FALSE;
|
g_atomic_int_set (&ready_time_dispatched, FALSE);
|
||||||
g_source_set_ready_time (source, 0);
|
g_source_set_ready_time (source, 0);
|
||||||
while (!ready_time_dispatched);
|
while (!g_atomic_int_get (&ready_time_dispatched));
|
||||||
|
|
||||||
/* kill the thread */
|
/* kill the thread */
|
||||||
g_main_loop_quit (loop);
|
g_main_loop_quit (loop);
|
||||||
|
Loading…
Reference in New Issue
Block a user