mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-29 00:46:16 +01:00
tests: Fix data races in gwakeuptest.c
This commit is contained in:
parent
1cc7457870
commit
68e78c6eb2
@ -116,19 +116,22 @@ context_clear (struct context *ctx)
|
|||||||
static void
|
static void
|
||||||
context_quit (struct context *ctx)
|
context_quit (struct context *ctx)
|
||||||
{
|
{
|
||||||
ctx->quit = TRUE;
|
g_atomic_int_set (&ctx->quit, TRUE);
|
||||||
g_wakeup_signal (ctx->wakeup);
|
g_wakeup_signal (ctx->wakeup);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct token *
|
static struct token *
|
||||||
context_pop_token (struct context *ctx)
|
context_try_pop_token (struct context *ctx)
|
||||||
{
|
{
|
||||||
struct token *token;
|
struct token *token = NULL;
|
||||||
|
|
||||||
g_mutex_lock (&ctx->lock);
|
g_mutex_lock (&ctx->lock);
|
||||||
|
if (ctx->pending_tokens != NULL)
|
||||||
|
{
|
||||||
token = ctx->pending_tokens->data;
|
token = ctx->pending_tokens->data;
|
||||||
ctx->pending_tokens = g_slist_delete_link (ctx->pending_tokens,
|
ctx->pending_tokens = g_slist_delete_link (ctx->pending_tokens,
|
||||||
ctx->pending_tokens);
|
ctx->pending_tokens);
|
||||||
|
}
|
||||||
g_mutex_unlock (&ctx->lock);
|
g_mutex_unlock (&ctx->lock);
|
||||||
|
|
||||||
return token;
|
return token;
|
||||||
@ -188,17 +191,15 @@ static gpointer
|
|||||||
thread_func (gpointer data)
|
thread_func (gpointer data)
|
||||||
{
|
{
|
||||||
struct context *ctx = data;
|
struct context *ctx = data;
|
||||||
|
struct token *token;
|
||||||
|
|
||||||
while (!ctx->quit)
|
while (!g_atomic_int_get (&ctx->quit))
|
||||||
{
|
{
|
||||||
wait_for_signaled (ctx->wakeup);
|
wait_for_signaled (ctx->wakeup);
|
||||||
g_wakeup_acknowledge (ctx->wakeup);
|
g_wakeup_acknowledge (ctx->wakeup);
|
||||||
|
|
||||||
while (ctx->pending_tokens)
|
while ((token = context_try_pop_token (ctx)) != NULL)
|
||||||
{
|
{
|
||||||
struct token *token;
|
|
||||||
|
|
||||||
token = context_pop_token (ctx);
|
|
||||||
g_assert (token->owner == ctx);
|
g_assert (token->owner == ctx);
|
||||||
dispatch_token (token);
|
dispatch_token (token);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user