4 /* We test deprecated functionality here */
5 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
10 const gchar *block = "0123456789ABCDEF";
13 p = g_slice_copy (12, block);
14 g_assert (memcmp (p, block, 12) == 0);
15 g_slice_free1 (12, p);
29 TestStruct *ts, *head;
31 head = ts = g_slice_new (TestStruct);
32 ts->next = g_slice_new (TestStruct);
34 ts->next = g_slice_new (TestStruct);
38 g_slice_free_chain (TestStruct, head, next);
41 static gpointer chunks[4096][30];
44 thread_allocate (gpointer data)
50 gpointer *loc; /* (atomic) */
52 for (i = 0; i < 10000; i++)
54 b = g_random_int_range (0, 30);
55 size = g_random_int_range (0, 4096);
56 loc = &(chunks[size][b]);
58 p = g_atomic_pointer_get (loc);
61 p = g_slice_alloc (size + 1);
62 if (!g_atomic_pointer_compare_and_exchange (loc, NULL, p))
63 g_slice_free1 (size + 1, p);
67 if (g_atomic_pointer_compare_and_exchange (loc, p, NULL))
68 g_slice_free1 (size + 1, p);
82 for (i = 0; i < 30; i++)
83 for (size = 1; size <= 4096; size++)
84 chunks[size - 1][i] = NULL;
86 for (i = 0; i < G_N_ELEMENTS(threads); i++)
87 threads[i] = g_thread_create (thread_allocate, NULL, TRUE, NULL);
89 for (i = 0; i < G_N_ELEMENTS(threads); i++)
90 g_thread_join (threads[i]);
94 main (int argc, char **argv)
96 g_test_init (&argc, &argv, NULL);
98 g_test_add_func ("/slice/copy", test_slice_copy);
99 g_test_add_func ("/slice/chain", test_chain);
100 g_test_add_func ("/slice/allocate", test_allocate);
102 return g_test_run ();