mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-21 22:59:16 +02:00
private: Use threading primitives correctly in private test
We shouldn't be clearing statically allocated mutexes, and also don't use deprecated heap-allocated GPrivate. https://bugzilla.gnome.org/show_bug.cgi?id=711755
This commit is contained in:
parent
177fe9f98e
commit
e34d74bdb3
@ -47,7 +47,6 @@ test_private1 (void)
|
|||||||
g_assert_cmpint (GPOINTER_TO_INT (value), ==, 2);
|
g_assert_cmpint (GPOINTER_TO_INT (value), ==, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GPrivate *private2;
|
|
||||||
static gint private2_destroy_count;
|
static gint private2_destroy_count;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -56,6 +55,8 @@ private2_destroy (gpointer data)
|
|||||||
g_atomic_int_inc (&private2_destroy_count);
|
g_atomic_int_inc (&private2_destroy_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GPrivate private2 = G_PRIVATE_INIT (private2_destroy);
|
||||||
|
|
||||||
static gpointer
|
static gpointer
|
||||||
private2_func (gpointer data)
|
private2_func (gpointer data)
|
||||||
{
|
{
|
||||||
@ -66,9 +67,9 @@ private2_func (gpointer data)
|
|||||||
for (i = 0; i < 1000; i++)
|
for (i = 0; i < 1000; i++)
|
||||||
{
|
{
|
||||||
v = value + (i % 5);
|
v = value + (i % 5);
|
||||||
g_private_set (private2, GINT_TO_POINTER(v));
|
g_private_set (&private2, GINT_TO_POINTER (v));
|
||||||
g_usleep (1000);
|
g_usleep (1000);
|
||||||
v2 = GPOINTER_TO_INT(g_private_get (private2));
|
v2 = GPOINTER_TO_INT (g_private_get (&private2));
|
||||||
g_assert_cmpint (v, ==, v2);
|
g_assert_cmpint (v, ==, v2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,10 +92,8 @@ test_private2 (void)
|
|||||||
GThread *thread[10];
|
GThread *thread[10];
|
||||||
gint i;
|
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++)
|
for (i = 0; i < 10; i++)
|
||||||
thread[i] = g_thread_create (private2_func, GINT_TO_POINTER (i), TRUE, NULL);
|
thread[i] = g_thread_create (private2_func, GINT_TO_POINTER (i), TRUE, NULL);
|
||||||
@ -369,10 +368,6 @@ test_static_private5 (void)
|
|||||||
|
|
||||||
for (i = 0; i < 10; i++)
|
for (i = 0; i < 10; i++)
|
||||||
g_thread_join (thread[i]);
|
g_thread_join (thread[i]);
|
||||||
|
|
||||||
g_mutex_clear (&m5);
|
|
||||||
g_cond_clear (&c5a);
|
|
||||||
g_cond_clear (&c5b);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
Loading…
x
Reference in New Issue
Block a user