[glib/wip/gcleanup] private: Use threading primitives correctly in private test
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/gcleanup] private: Use threading primitives correctly in private test
- Date: Thu, 7 Nov 2013 22:03:06 +0000 (UTC)
commit 15759c7b2bc66a71fc5a9e7f80738ce9dc26cd75
Author: Stef Walter <stefw gnome org>
Date: Thu Nov 7 22:40:40 2013 +0100
private: Use threading primitives correctly in private test
glib/tests/private.c | 17 ++++++-----------
1 files changed, 6 insertions(+), 11 deletions(-)
---
diff --git a/glib/tests/private.c b/glib/tests/private.c
index 52bc38b..803d2dd 100644
--- a/glib/tests/private.c
+++ b/glib/tests/private.c
@@ -48,7 +48,6 @@ test_private1 (void)
g_assert_cmpint (GPOINTER_TO_INT (value), ==, 2);
}
-static GPrivate *private2;
static gint private2_destroy_count;
static void
@@ -57,6 +56,8 @@ private2_destroy (gpointer data)
g_atomic_int_inc (&private2_destroy_count);
}
+static GPrivate private2 = G_PRIVATE_INIT (private2_destroy);
+
static gpointer
private2_func (gpointer data)
{
@@ -67,9 +68,9 @@ private2_func (gpointer data)
for (i = 0; i < 1000; i++)
{
v = value + (i % 5);
- g_private_set (private2, GINT_TO_POINTER(v));
+ g_private_set (&private2, GINT_TO_POINTER(v));
g_usleep (1000);
- v2 = GPOINTER_TO_INT(g_private_get (private2));
+ v2 = GPOINTER_TO_INT(g_private_get (&private2));
g_assert_cmpint (v, ==, v2);
}
@@ -92,10 +93,8 @@ test_private2 (void)
GThread *thread[10];
gint i;
- private2 = g_private_new (private2_destroy);
-
- g_private_set (private2, GINT_TO_POINTER(234));
- g_private_replace (private2, GINT_TO_POINTER(123));
+ g_private_set (&private2, GINT_TO_POINTER(234));
+ g_private_replace (&private2, GINT_TO_POINTER(123));
for (i = 0; i < 10; i++)
thread[i] = g_thread_create (private2_func, GINT_TO_POINTER (i), TRUE, NULL);
@@ -370,10 +369,6 @@ test_static_private5 (void)
for (i = 0; i < 10; i++)
g_thread_join (thread[i]);
-
- g_mutex_clear (&m5);
- g_cond_clear (&c5a);
- g_cond_clear (&c5b);
}
G_CLEANUP_DEFINE
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]