1d81ac5339fcf9537a3731ebb5770238f4fa69d59Sebastian Wilhelmi#undef G_DISABLE_ASSERT
2d81ac5339fcf9537a3731ebb5770238f4fa69d59Sebastian Wilhelmi#undef G_LOG_DOMAIN
3d81ac5339fcf9537a3731ebb5770238f4fa69d59Sebastian Wilhelmi
490f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi#include <glib.h>
590f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
690f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi/* GMutex */
790f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
890f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmistatic GMutex* test_g_mutex_mutex = NULL;
990f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmistatic guint test_g_mutex_int = 0;
109c357424fc4de953afaf2aa09020b825bb5733abSebastian Wilhelmistatic gboolean test_g_mutex_thread_ready;
111383e5b64259c05b977442df2c473fa5931854a5Sebastian WilhelmiG_LOCK_DEFINE_STATIC (test_g_mutex);
1290f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
13cd00d6e2cc2b8ce90a44e838750faeacb6f779fcSebastian Wilhelmistatic gpointer
1490f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmitest_g_mutex_thread (gpointer data)
1590f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi{
1690f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  g_assert (GPOINTER_TO_INT (data) == 42);
1790f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  g_assert (g_mutex_trylock (test_g_mutex_mutex) == FALSE);
181383e5b64259c05b977442df2c473fa5931854a5Sebastian Wilhelmi  g_assert (G_TRYLOCK (test_g_mutex) == FALSE);
199c357424fc4de953afaf2aa09020b825bb5733abSebastian Wilhelmi  test_g_mutex_thread_ready = TRUE;
2090f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  g_mutex_lock (test_g_mutex_mutex);
2190f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  g_assert (test_g_mutex_int == 42);
2290f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  g_mutex_unlock (test_g_mutex_mutex);
23cd00d6e2cc2b8ce90a44e838750faeacb6f779fcSebastian Wilhelmi
24cd00d6e2cc2b8ce90a44e838750faeacb6f779fcSebastian Wilhelmi  return GINT_TO_POINTER (41);
2590f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi}
2690f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
2790f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmistatic void
2890f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmitest_g_mutex (void)
2990f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi{
3090f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  GThread *thread;
3190f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  test_g_mutex_mutex = g_mutex_new ();
3290f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
3390f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  g_assert (g_mutex_trylock (test_g_mutex_mutex));
341383e5b64259c05b977442df2c473fa5931854a5Sebastian Wilhelmi  g_assert (G_TRYLOCK (test_g_mutex));
359c357424fc4de953afaf2aa09020b825bb5733abSebastian Wilhelmi  test_g_mutex_thread_ready = FALSE;
36227d18bc469fb00c8c506121c0ae30b453991407Sebastian Wilhelmi  thread = g_thread_create (test_g_mutex_thread, GINT_TO_POINTER (42),
37227d18bc469fb00c8c506121c0ae30b453991407Sebastian Wilhelmi			    TRUE, NULL);
389c357424fc4de953afaf2aa09020b825bb5733abSebastian Wilhelmi  /* This busy wait is only for testing purposes and not an example of
399c357424fc4de953afaf2aa09020b825bb5733abSebastian Wilhelmi   * good code!*/
409c357424fc4de953afaf2aa09020b825bb5733abSebastian Wilhelmi  while (!test_g_mutex_thread_ready)
419c357424fc4de953afaf2aa09020b825bb5733abSebastian Wilhelmi    g_usleep (G_USEC_PER_SEC / 5);
4290f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  test_g_mutex_int = 42;
431383e5b64259c05b977442df2c473fa5931854a5Sebastian Wilhelmi  G_UNLOCK (test_g_mutex);
4490f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  g_mutex_unlock (test_g_mutex_mutex);
45cd00d6e2cc2b8ce90a44e838750faeacb6f779fcSebastian Wilhelmi  g_assert (GPOINTER_TO_INT (g_thread_join (thread)) == 41);
4690f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  g_mutex_free (test_g_mutex_mutex);
4790f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi}
4890f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
4990f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi/* GStaticRecMutex */
5090f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
5190f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmistatic GStaticRecMutex test_g_static_rec_mutex_mutex = G_STATIC_REC_MUTEX_INIT;
5290f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmistatic guint test_g_static_rec_mutex_int = 0;
539c357424fc4de953afaf2aa09020b825bb5733abSebastian Wilhelmistatic gboolean test_g_static_rec_mutex_thread_ready;
5490f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
55cd00d6e2cc2b8ce90a44e838750faeacb6f779fcSebastian Wilhelmistatic gpointer
5690f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmitest_g_static_rec_mutex_thread (gpointer data)
5790f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi{
5890f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  g_assert (GPOINTER_TO_INT (data) == 42);
5990f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  g_assert (g_static_rec_mutex_trylock (&test_g_static_rec_mutex_mutex)
6090f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	    == FALSE);
619c357424fc4de953afaf2aa09020b825bb5733abSebastian Wilhelmi  test_g_static_rec_mutex_thread_ready = TRUE;
6290f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  g_static_rec_mutex_lock (&test_g_static_rec_mutex_mutex);
6390f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  g_static_rec_mutex_lock (&test_g_static_rec_mutex_mutex);
6490f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  g_assert (test_g_static_rec_mutex_int == 42);
659c357424fc4de953afaf2aa09020b825bb5733abSebastian Wilhelmi  test_g_static_rec_mutex_thread_ready = FALSE;
6690f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  g_static_rec_mutex_unlock (&test_g_static_rec_mutex_mutex);
6790f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  g_static_rec_mutex_unlock (&test_g_static_rec_mutex_mutex);
68cd00d6e2cc2b8ce90a44e838750faeacb6f779fcSebastian Wilhelmi
69cd00d6e2cc2b8ce90a44e838750faeacb6f779fcSebastian Wilhelmi  g_thread_exit (GINT_TO_POINTER (43));
70cd00d6e2cc2b8ce90a44e838750faeacb6f779fcSebastian Wilhelmi
71cd00d6e2cc2b8ce90a44e838750faeacb6f779fcSebastian Wilhelmi  g_assert_not_reached ();
72cd00d6e2cc2b8ce90a44e838750faeacb6f779fcSebastian Wilhelmi  return NULL;
7390f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi}
7490f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
7590f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmistatic void
7690f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmitest_g_static_rec_mutex (void)
7790f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi{
7890f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  GThread *thread;
7990f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
8090f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  g_assert (g_static_rec_mutex_trylock (&test_g_static_rec_mutex_mutex));
819c357424fc4de953afaf2aa09020b825bb5733abSebastian Wilhelmi  test_g_static_rec_mutex_thread_ready = FALSE;
8290f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  thread = g_thread_create (test_g_static_rec_mutex_thread,
83227d18bc469fb00c8c506121c0ae30b453991407Sebastian Wilhelmi			    GINT_TO_POINTER (42), TRUE, NULL);
849c357424fc4de953afaf2aa09020b825bb5733abSebastian Wilhelmi  /* This busy wait is only for testing purposes and not an example of
859c357424fc4de953afaf2aa09020b825bb5733abSebastian Wilhelmi   * good code!*/
869c357424fc4de953afaf2aa09020b825bb5733abSebastian Wilhelmi  while (!test_g_static_rec_mutex_thread_ready)
879c357424fc4de953afaf2aa09020b825bb5733abSebastian Wilhelmi    g_usleep (G_USEC_PER_SEC / 5);
889c357424fc4de953afaf2aa09020b825bb5733abSebastian Wilhelmi
8990f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  g_assert (g_static_rec_mutex_trylock (&test_g_static_rec_mutex_mutex));
9090f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  test_g_static_rec_mutex_int = 41;
9190f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  g_static_rec_mutex_unlock (&test_g_static_rec_mutex_mutex);
9290f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  test_g_static_rec_mutex_int = 42;
9390f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  g_static_rec_mutex_unlock (&test_g_static_rec_mutex_mutex);
949c357424fc4de953afaf2aa09020b825bb5733abSebastian Wilhelmi
959c357424fc4de953afaf2aa09020b825bb5733abSebastian Wilhelmi  /* This busy wait is only for testing purposes and not an example of
969c357424fc4de953afaf2aa09020b825bb5733abSebastian Wilhelmi   * good code!*/
979c357424fc4de953afaf2aa09020b825bb5733abSebastian Wilhelmi  while (test_g_static_rec_mutex_thread_ready)
989c357424fc4de953afaf2aa09020b825bb5733abSebastian Wilhelmi    g_usleep (G_USEC_PER_SEC / 5);
999c357424fc4de953afaf2aa09020b825bb5733abSebastian Wilhelmi
10090f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  g_static_rec_mutex_lock (&test_g_static_rec_mutex_mutex);
10190f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  test_g_static_rec_mutex_int = 0;
10290f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  g_static_rec_mutex_unlock (&test_g_static_rec_mutex_mutex);
103cd00d6e2cc2b8ce90a44e838750faeacb6f779fcSebastian Wilhelmi
104cd00d6e2cc2b8ce90a44e838750faeacb6f779fcSebastian Wilhelmi  g_assert (GPOINTER_TO_INT (g_thread_join (thread)) == 43);
10590f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi}
10690f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
10790f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi/* GStaticPrivate */
10890f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
10990f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi#define THREADS 10
11090f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
11141e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmistatic GStaticPrivate test_g_static_private_private1 = G_STATIC_PRIVATE_INIT;
11241e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmistatic GStaticPrivate test_g_static_private_private2 = G_STATIC_PRIVATE_INIT;
11390f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmistatic GStaticMutex test_g_static_private_mutex = G_STATIC_MUTEX_INIT;
11490f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmistatic guint test_g_static_private_counter = 0;
11541e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmistatic guint test_g_static_private_ready = 0;
11690f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
11790f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmistatic gpointer
11890f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmitest_g_static_private_constructor (void)
11990f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi{
12090f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  g_static_mutex_lock (&test_g_static_private_mutex);
12190f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  test_g_static_private_counter++;
12290f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  g_static_mutex_unlock (&test_g_static_private_mutex);
12390f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  return g_new (guint,1);
12490f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi}
12590f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
12690f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmistatic void
12790f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmitest_g_static_private_destructor (gpointer data)
12890f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi{
12990f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  g_static_mutex_lock (&test_g_static_private_mutex);
13090f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  test_g_static_private_counter--;
13190f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  g_static_mutex_unlock (&test_g_static_private_mutex);
13290f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  g_free (data);
13390f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi}
13490f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
13590f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
136cd00d6e2cc2b8ce90a44e838750faeacb6f779fcSebastian Wilhelmistatic gpointer
13790f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmitest_g_static_private_thread (gpointer data)
13890f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi{
13990f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  guint number = GPOINTER_TO_INT (data);
14090f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  guint i;
14141e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi  guint *private1, *private2;
14290f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  for (i = 0; i < 10; i++)
14390f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi    {
14490f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi      number = number * 11 + 1; /* A very simple and bad RNG ;-) */
14541e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi      private1 = g_static_private_get (&test_g_static_private_private1);
14641e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi      if (!private1 || number % 7 > 3)
14790f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	{
14841e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi	  private1 = test_g_static_private_constructor ();
14941e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi	  g_static_private_set (&test_g_static_private_private1, private1,
15090f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi				test_g_static_private_destructor);
15190f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	}
15241e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi      *private1 = number;
15341e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi      private2 = g_static_private_get (&test_g_static_private_private2);
15441e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi      if (!private2 || number % 13 > 5)
15541e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi	{
15641e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi	  private2 = test_g_static_private_constructor ();
15741e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi	  g_static_private_set (&test_g_static_private_private2, private2,
15841e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi				test_g_static_private_destructor);
15941e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi	}
16041e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi      *private2 = number * 2;
16141e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi      g_usleep (G_USEC_PER_SEC / 5);
16241e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi      g_assert (number == *private1);
16341e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi      g_assert (number * 2 == *private2);
16441e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi    }
16541e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi  g_static_mutex_lock (&test_g_static_private_mutex);
16641e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi  test_g_static_private_ready++;
16741e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi  g_static_mutex_unlock (&test_g_static_private_mutex);
16841e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi
16941e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi  /* Busy wait is not nice but that's just a test */
17041e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi  while (test_g_static_private_ready != 0)
17141e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi    g_usleep (G_USEC_PER_SEC / 5);
17241e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi
17341e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi  for (i = 0; i < 10; i++)
17441e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi    {
17541e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi      private2 = g_static_private_get (&test_g_static_private_private2);
17641e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi      number = number * 11 + 1; /* A very simple and bad RNG ;-) */
17741e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi      if (!private2 || number % 13 > 5)
17841e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi	{
17941e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi	  private2 = test_g_static_private_constructor ();
18041e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi	  g_static_private_set (&test_g_static_private_private2, private2,
18141e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi				test_g_static_private_destructor);
18241e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi	}
18341e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi      *private2 = number * 2;
184ef2dcd6265bcd52a24fc12cfa8f769f899e13653Sebastian Wilhelmi      g_usleep (G_USEC_PER_SEC / 5);
18541e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi      g_assert (number * 2 == *private2);
18690f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi    }
187cd00d6e2cc2b8ce90a44e838750faeacb6f779fcSebastian Wilhelmi
188cd00d6e2cc2b8ce90a44e838750faeacb6f779fcSebastian Wilhelmi  return GINT_TO_POINTER (GPOINTER_TO_INT (data) * 3);
18990f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi}
19090f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
19190f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmistatic void
19290f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmitest_g_static_private (void)
19390f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi{
19490f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  GThread *threads[THREADS];
19590f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  guint i;
19641e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi
19741e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi  test_g_static_private_ready = 0;
19841e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi
19990f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  for (i = 0; i < THREADS; i++)
20090f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi    {
20190f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi      threads[i] = g_thread_create (test_g_static_private_thread,
202227d18bc469fb00c8c506121c0ae30b453991407Sebastian Wilhelmi				    GINT_TO_POINTER (i), TRUE, NULL);
20390f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi    }
20441e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi
20541e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi  /* Busy wait is not nice but that's just a test */
20641e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi  while (test_g_static_private_ready != THREADS)
20741e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi    g_usleep (G_USEC_PER_SEC / 5);
20841e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi
20941e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi  /* Reuse the static private */
21041e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi  g_static_private_free (&test_g_static_private_private2);
21141e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi  g_static_private_init (&test_g_static_private_private2);
21241e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi
21341e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi  test_g_static_private_ready = 0;
21441e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi
21590f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  for (i = 0; i < THREADS; i++)
216cd00d6e2cc2b8ce90a44e838750faeacb6f779fcSebastian Wilhelmi    g_assert (GPOINTER_TO_INT (g_thread_join (threads[i])) == i * 3);
217cd00d6e2cc2b8ce90a44e838750faeacb6f779fcSebastian Wilhelmi
21890f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  g_assert (test_g_static_private_counter == 0);
21990f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi}
22090f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
22190f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi/* GStaticRWLock */
22290f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
22390f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi/* -1 = writing; >0 = # of readers */
22490f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmistatic gint test_g_static_rw_lock_state = 0;
22590f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian WilhelmiG_LOCK_DEFINE (test_g_static_rw_lock_state);
22690f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
22790f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmistatic gboolean test_g_static_rw_lock_run = TRUE;
22890f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmistatic GStaticRWLock test_g_static_rw_lock_lock = G_STATIC_RW_LOCK_INIT;
22990f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
230cd00d6e2cc2b8ce90a44e838750faeacb6f779fcSebastian Wilhelmistatic gpointer
23190f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmitest_g_static_rw_lock_thread (gpointer data)
23290f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi{
23390f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  while (test_g_static_rw_lock_run)
23490f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi    {
23590f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi      if (g_random_double() > .2) /* I'm a reader */
23690f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	{
23790f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
23890f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	  if (g_random_double() > .2) /* I'll block */
23990f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	    g_static_rw_lock_reader_lock (&test_g_static_rw_lock_lock);
24090f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	  else /* I'll only try */
24190f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	    if (!g_static_rw_lock_reader_trylock (&test_g_static_rw_lock_lock))
24290f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	      continue;
24390f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	  G_LOCK (test_g_static_rw_lock_state);
24490f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	  g_assert (test_g_static_rw_lock_state >= 0);
24590f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	  test_g_static_rw_lock_state++;
24690f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	  G_UNLOCK (test_g_static_rw_lock_state);
24790f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
2489c357424fc4de953afaf2aa09020b825bb5733abSebastian Wilhelmi	  g_usleep (g_random_int_range (20,1000));
24990f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
25090f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	  G_LOCK (test_g_static_rw_lock_state);
25190f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	  test_g_static_rw_lock_state--;
25290f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	  G_UNLOCK (test_g_static_rw_lock_state);
25390f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
25490f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	  g_static_rw_lock_reader_unlock (&test_g_static_rw_lock_lock);
25590f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	}
25690f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi      else /* I'm a writer */
25790f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	{
25890f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
25990f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	  if (g_random_double() > .2) /* I'll block */
26090f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	    g_static_rw_lock_writer_lock (&test_g_static_rw_lock_lock);
26190f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	  else /* I'll only try */
26290f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	    if (!g_static_rw_lock_writer_trylock (&test_g_static_rw_lock_lock))
26390f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	      continue;
26490f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	  G_LOCK (test_g_static_rw_lock_state);
26590f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	  g_assert (test_g_static_rw_lock_state == 0);
26690f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	  test_g_static_rw_lock_state = -1;
26790f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	  G_UNLOCK (test_g_static_rw_lock_state);
26890f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
2699c357424fc4de953afaf2aa09020b825bb5733abSebastian Wilhelmi	  g_usleep (g_random_int_range (20,1000));
27090f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
27190f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	  G_LOCK (test_g_static_rw_lock_state);
27290f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	  test_g_static_rw_lock_state = 0;
27390f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	  G_UNLOCK (test_g_static_rw_lock_state);
27490f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
27590f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	  g_static_rw_lock_writer_unlock (&test_g_static_rw_lock_lock);
27690f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi	}
27790f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi    }
278cd00d6e2cc2b8ce90a44e838750faeacb6f779fcSebastian Wilhelmi  return NULL;
27990f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi}
28090f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
28190f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmistatic void
28290f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmitest_g_static_rw_lock ()
28390f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi{
28490f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  GThread *threads[THREADS];
28590f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  guint i;
28690f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  for (i = 0; i < THREADS; i++)
28790f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi    {
28890f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi      threads[i] = g_thread_create (test_g_static_rw_lock_thread,
289227d18bc469fb00c8c506121c0ae30b453991407Sebastian Wilhelmi				    NULL, TRUE, NULL);
29090f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi    }
2919c357424fc4de953afaf2aa09020b825bb5733abSebastian Wilhelmi  g_usleep (G_USEC_PER_SEC * 5);
29290f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  test_g_static_rw_lock_run = FALSE;
29390f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  for (i = 0; i < THREADS; i++)
29490f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi    {
29590f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi      g_thread_join (threads[i]);
29690f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi    }
29790f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  g_assert (test_g_static_rw_lock_state == 0);
29890f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi}
29990f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi
300876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen#define G_ONCE_SIZE 100
301876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen#define G_ONCE_THREADS 10
302876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen
303876f9078636e9543a3fec402f13a00dca2af9f41Matthias ClasenG_LOCK_DEFINE (test_g_once);
304876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasenstatic guint test_g_once_guint_array[G_ONCE_SIZE];
305876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasenstatic GOnce test_g_once_array[G_ONCE_SIZE];
306876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen
307876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasenstatic gpointer
308876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasentest_g_once_init_func(gpointer arg)
309876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen{
310876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen  guint *count = arg;
311876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen  g_usleep (g_random_int_range (20,1000));
312876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen  (*count)++;
313876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen  g_usleep (g_random_int_range (20,1000));
314876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen  return arg;
315876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen}
316876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen
317876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasenstatic gpointer
318876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasentest_g_once_thread (gpointer ignore)
319876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen{
320876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen  guint i;
321876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen  G_LOCK (test_g_once);
322876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen  /* Don't start before all threads are created */
323876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen  G_UNLOCK (test_g_once);
324876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen  for (i = 0; i < 1000; i++)
325876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen    {
326876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen      guint pos = g_random_int_range (0, G_ONCE_SIZE);
327876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen      gpointer ret = g_once (test_g_once_array + pos, test_g_once_init_func,
328876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen			     test_g_once_guint_array + pos);
329876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen      g_assert (ret == test_g_once_guint_array + pos);
330876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen    }
331876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen
332876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen  /* Make sure, that all counters are touched at least once */
333876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen  for (i = 0; i < G_ONCE_SIZE; i++)
334876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen    {
335876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen      gpointer ret = g_once (test_g_once_array + i, test_g_once_init_func,
336876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen			     test_g_once_guint_array + i);
337876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen      g_assert (ret == test_g_once_guint_array + i);
338876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen    }
339876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen
340876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen  return NULL;
341876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen}
342876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen
343876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasenstatic void
344876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasentest_g_thread_once (void)
345876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen{
346876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen  static GOnce once_init = G_ONCE_INIT;
347876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen  GThread *threads[G_ONCE_THREADS];
348876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen  guint i;
349876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen  for (i = 0; i < G_ONCE_SIZE; i++)
350876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen    {
351876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen      test_g_once_array[i] = once_init;
352876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen      test_g_once_guint_array[i] = i;
353876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen    }
354876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen  G_LOCK (test_g_once);
355876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen  for (i = 0; i < G_ONCE_THREADS; i++)
356876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen    {
3572b789552985c20a19f8450cfe6afd057b550bfe1Manish Singh      threads[i] = g_thread_create (test_g_once_thread, GUINT_TO_POINTER(i%2),
358876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen				    TRUE, NULL);
359876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen    }
360876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen  G_UNLOCK (test_g_once);
361876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen  for (i = 0; i < G_ONCE_THREADS; i++)
362876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen    {
363876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen      g_thread_join (threads[i]);
364876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen    }
365876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen
366876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen  for (i = 0; i < G_ONCE_SIZE; i++)
367876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen    {
368876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen      g_assert (test_g_once_guint_array[i] == i + 1);
369876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen    }
370876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen}
371876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen
37290f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi/* run all the tests */
3735e7134375eea0543c998715e03a458411906e89cSebastian Wilhelmivoid
3745e7134375eea0543c998715e03a458411906e89cSebastian Wilhelmirun_all_tests()
3755e7134375eea0543c998715e03a458411906e89cSebastian Wilhelmi{
3765e7134375eea0543c998715e03a458411906e89cSebastian Wilhelmi  test_g_mutex ();
3775e7134375eea0543c998715e03a458411906e89cSebastian Wilhelmi  test_g_static_rec_mutex ();
3785e7134375eea0543c998715e03a458411906e89cSebastian Wilhelmi  test_g_static_private ();
37941e2001d85966ce3bd9133e49b070a00926bd6eaSebastian Wilhelmi  test_g_static_rw_lock ();
380876f9078636e9543a3fec402f13a00dca2af9f41Matthias Clasen  test_g_thread_once ();
3815e7134375eea0543c998715e03a458411906e89cSebastian Wilhelmi}
3825e7134375eea0543c998715e03a458411906e89cSebastian Wilhelmi
38390f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmiint
38490f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmimain (int   argc,
38590f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi      char *argv[])
38690f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi{
38790f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  /* Only run the test, if threads are enabled and a default thread
38890f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi     implementation is available */
38990f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi#if defined(G_THREADS_ENABLED) && ! defined(G_THREADS_IMPL_NONE)
39090f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  g_thread_init (NULL);
3915e7134375eea0543c998715e03a458411906e89cSebastian Wilhelmi  run_all_tests ();
3925e7134375eea0543c998715e03a458411906e89cSebastian Wilhelmi
3935e7134375eea0543c998715e03a458411906e89cSebastian Wilhelmi  /* Now we rerun all tests, but this time we fool the system into
3945e7134375eea0543c998715e03a458411906e89cSebastian Wilhelmi   * thinking, that the available thread system is not native, but
3955e7134375eea0543c998715e03a458411906e89cSebastian Wilhelmi   * userprovided. */
3965e7134375eea0543c998715e03a458411906e89cSebastian Wilhelmi
3975e7134375eea0543c998715e03a458411906e89cSebastian Wilhelmi  g_thread_use_default_impl = FALSE;
3985e7134375eea0543c998715e03a458411906e89cSebastian Wilhelmi  run_all_tests ();
3995e7134375eea0543c998715e03a458411906e89cSebastian Wilhelmi
40090f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi#endif
40190f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi  return 0;
40290f6cc9bf2453e5da385b2d547704091dd8afbb8Sebastian Wilhelmi}
403