Stop using GStaticMutex in two testcases

This commit is contained in:
Ryan Lortie 2011-09-17 19:33:30 -04:00
parent 1da913a7a3
commit c33cd00739
2 changed files with 13 additions and 15 deletions

View File

@ -78,7 +78,7 @@ struct token
struct context struct context
{ {
GSList *pending_tokens; GSList *pending_tokens;
GStaticMutex lock; GMutex lock;
GWakeup *wakeup; GWakeup *wakeup;
gboolean quit; gboolean quit;
}; };
@ -95,10 +95,8 @@ static volatile gint tokens_alive;
static void static void
context_init (struct context *ctx) context_init (struct context *ctx)
{ {
GStaticMutex lock = G_STATIC_MUTEX_INIT;
ctx->pending_tokens = NULL; ctx->pending_tokens = NULL;
ctx->lock = lock; g_mutex_init (&ctx->lock);
ctx->wakeup = g_wakeup_new (); ctx->wakeup = g_wakeup_new ();
ctx->quit = FALSE; ctx->quit = FALSE;
} }
@ -124,11 +122,11 @@ context_pop_token (struct context *ctx)
{ {
struct token *token; struct token *token;
g_static_mutex_lock (&ctx->lock); g_mutex_lock (&ctx->lock);
token = ctx->pending_tokens->data; token = ctx->pending_tokens->data;
ctx->pending_tokens = g_slist_remove_link (ctx->pending_tokens, ctx->pending_tokens = g_slist_remove_link (ctx->pending_tokens,
ctx->pending_tokens); ctx->pending_tokens);
g_static_mutex_unlock (&ctx->lock); g_mutex_unlock (&ctx->lock);
return token; return token;
} }
@ -139,9 +137,9 @@ context_push_token (struct context *ctx,
{ {
g_assert (token->owner == ctx); g_assert (token->owner == ctx);
g_static_mutex_lock (&ctx->lock); g_mutex_lock (&ctx->lock);
ctx->pending_tokens = g_slist_prepend (ctx->pending_tokens, token); ctx->pending_tokens = g_slist_prepend (ctx->pending_tokens, token);
g_static_mutex_unlock (&ctx->lock); g_mutex_unlock (&ctx->lock);
g_wakeup_signal (ctx->wakeup); g_wakeup_signal (ctx->wakeup);
} }

View File

@ -110,25 +110,25 @@ test_g_static_rec_mutex (void)
static GStaticPrivate test_g_static_private_private1 = G_STATIC_PRIVATE_INIT; static GStaticPrivate test_g_static_private_private1 = G_STATIC_PRIVATE_INIT;
static GStaticPrivate test_g_static_private_private2 = G_STATIC_PRIVATE_INIT; static GStaticPrivate test_g_static_private_private2 = G_STATIC_PRIVATE_INIT;
static GStaticMutex test_g_static_private_mutex = G_STATIC_MUTEX_INIT; static GMutex test_g_static_private_mutex = G_MUTEX_INIT;
static guint test_g_static_private_counter = 0; static guint test_g_static_private_counter = 0;
static guint test_g_static_private_ready = 0; static guint test_g_static_private_ready = 0;
static gpointer static gpointer
test_g_static_private_constructor (void) test_g_static_private_constructor (void)
{ {
g_static_mutex_lock (&test_g_static_private_mutex); g_mutex_lock (&test_g_static_private_mutex);
test_g_static_private_counter++; test_g_static_private_counter++;
g_static_mutex_unlock (&test_g_static_private_mutex); g_mutex_unlock (&test_g_static_private_mutex);
return g_new (guint,1); return g_new (guint,1);
} }
static void static void
test_g_static_private_destructor (gpointer data) test_g_static_private_destructor (gpointer data)
{ {
g_static_mutex_lock (&test_g_static_private_mutex); g_mutex_lock (&test_g_static_private_mutex);
test_g_static_private_counter--; test_g_static_private_counter--;
g_static_mutex_unlock (&test_g_static_private_mutex); g_mutex_unlock (&test_g_static_private_mutex);
g_free (data); g_free (data);
} }
@ -162,9 +162,9 @@ test_g_static_private_thread (gpointer data)
g_assert (number == *private1); g_assert (number == *private1);
g_assert (number * 2 == *private2); g_assert (number * 2 == *private2);
} }
g_static_mutex_lock (&test_g_static_private_mutex); g_mutex_lock (&test_g_static_private_mutex);
test_g_static_private_ready++; test_g_static_private_ready++;
g_static_mutex_unlock (&test_g_static_private_mutex); g_mutex_unlock (&test_g_static_private_mutex);
/* Busy wait is not nice but that's just a test */ /* Busy wait is not nice but that's just a test */
while (test_g_static_private_ready != 0) while (test_g_static_private_ready != 0)