mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-20 22:29:17 +02:00
Merge branch 'tests-tsan' into 'master'
tests: Fix some data races in tests See merge request GNOME/glib!453
This commit is contained in:
commit
e0148985f3
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -153,19 +153,11 @@ my_test_class_init (GTestClass *klass)
|
|||||||
klass->test_signal2 = my_test_test_signal2;
|
klass->test_signal2 = my_test_test_signal2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline guint32
|
|
||||||
quick_rand32 (void)
|
|
||||||
{
|
|
||||||
static guint32 accu = 2147483563;
|
|
||||||
accu = 1664525 * accu + 1013904223;
|
|
||||||
return accu;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_closure (GClosure *closure)
|
test_closure (GClosure *closure)
|
||||||
{
|
{
|
||||||
/* try to produce high contention in closure->ref_count */
|
/* try to produce high contention in closure->ref_count */
|
||||||
guint i = 0, n = quick_rand32() % 199;
|
guint i = 0, n = g_random_int () % 199;
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++)
|
||||||
g_closure_ref (closure);
|
g_closure_ref (closure);
|
||||||
g_closure_sink (closure); /* NOP */
|
g_closure_sink (closure); /* NOP */
|
||||||
|
@ -12,8 +12,6 @@
|
|||||||
#define MY_IS_TEST_CLASS(tclass) (G_TYPE_CHECK_CLASS_TYPE ((tclass), G_TYPE_TEST))
|
#define MY_IS_TEST_CLASS(tclass) (G_TYPE_CHECK_CLASS_TYPE ((tclass), G_TYPE_TEST))
|
||||||
#define MY_TEST_GET_CLASS(test) (G_TYPE_INSTANCE_GET_CLASS ((test), G_TYPE_TEST, GTestClass))
|
#define MY_TEST_GET_CLASS(test) (G_TYPE_INSTANCE_GET_CLASS ((test), G_TYPE_TEST, GTestClass))
|
||||||
|
|
||||||
static GRand *grand;
|
|
||||||
|
|
||||||
typedef struct _GTest GTest;
|
typedef struct _GTest GTest;
|
||||||
typedef struct _GTestClass GTestClass;
|
typedef struct _GTestClass GTestClass;
|
||||||
|
|
||||||
@ -34,7 +32,7 @@ struct _GTestClass
|
|||||||
};
|
};
|
||||||
|
|
||||||
static GType my_test_get_type (void);
|
static GType my_test_get_type (void);
|
||||||
static volatile gboolean stopping;
|
static gboolean stopping;
|
||||||
|
|
||||||
/* Element signals and args */
|
/* Element signals and args */
|
||||||
enum
|
enum
|
||||||
@ -87,8 +85,6 @@ my_test_get_type (void)
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
grand = g_rand_new();
|
|
||||||
|
|
||||||
test_type = g_type_register_static (G_TYPE_OBJECT, "GTest",
|
test_type = g_type_register_static (G_TYPE_OBJECT, "GTest",
|
||||||
&test_info, 0);
|
&test_info, 0);
|
||||||
}
|
}
|
||||||
@ -221,7 +217,7 @@ my_test_do_signal3 (GTest * test)
|
|||||||
static void
|
static void
|
||||||
my_test_do_prop (GTest * test)
|
my_test_do_prop (GTest * test)
|
||||||
{
|
{
|
||||||
test->value = g_rand_int (grand);
|
test->value = g_random_int ();
|
||||||
g_object_notify (G_OBJECT (test), "test-prop");
|
g_object_notify (G_OBJECT (test), "test-prop");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,7 +226,7 @@ run_thread (GTest * test)
|
|||||||
{
|
{
|
||||||
gint i = 1;
|
gint i = 1;
|
||||||
|
|
||||||
while (!stopping) {
|
while (!g_atomic_int_get (&stopping)) {
|
||||||
if (TESTNUM == 1)
|
if (TESTNUM == 1)
|
||||||
my_test_do_signal1 (test);
|
my_test_do_signal1 (test);
|
||||||
if (TESTNUM == 2)
|
if (TESTNUM == 2)
|
||||||
@ -290,7 +286,7 @@ main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
g_usleep (5000000);
|
g_usleep (5000000);
|
||||||
|
|
||||||
stopping = TRUE;
|
g_atomic_int_set (&stopping, TRUE);
|
||||||
|
|
||||||
g_print ("\nstopping\n");
|
g_print ("\nstopping\n");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user