#include <string.h>
#define quick_rand32() (rand_accu = 1664525 * rand_accu + 1013904223, rand_accu)
-static guint prime_size = 1021; // 769; // 509
+static guint prime_size = 1021; /* 769; 509 */
static gboolean clean_memchunks = FALSE;
static guint number_of_blocks = 10000; /* total number of blocks allocated */
static guint number_of_repetitions = 10000; /* number of alloc+free repetitions */
test_sliced_mem_thread (gpointer data)
{
guint32 rand_accu = 2147483563;
+ guint i, j;
+ guint8 **ps;
+ guint *ss;
+
/* initialize random numbers */
if (data)
rand_accu = *(guint32*) data;
rand_accu = rand_tv.tv_usec + (rand_tv.tv_sec << 16);
}
- guint i, j;
- guint8 **ps = g_new (guint8*, number_of_blocks);
- guint *ss = g_new (guint, number_of_blocks);
+ ps = g_new (guint8*, number_of_blocks);
+ ss = g_new (guint, number_of_blocks);
/* create number_of_blocks random sizes */
for (i = 0; i < number_of_blocks; i++)
ss[i] = quick_rand32() % prime_size;
if (argc <= 1)
usage();
- gchar strseed[64] = "<random>";
- if (seedp)
- g_snprintf (strseed, 64, "%u", *seedp);
- g_print ("Starting %d threads allocating random blocks <= %u bytes with seed=%s using %s%s\n", n_threads, prime_size, strseed, mode, emode);
+ {
+ gchar strseed[64] = "<random>";
+ GThread **threads;
+ guint i;
+
+ if (seedp)
+ g_snprintf (strseed, 64, "%u", *seedp);
+ g_print ("Starting %d threads allocating random blocks <= %u bytes with seed=%s using %s%s\n", n_threads, prime_size, strseed, mode, emode);
- GThread *threads[n_threads];
- guint i;
- if (!use_memchunks)
- for (i = 0; i < n_threads; i++)
- threads[i] = g_thread_create_full (test_sliced_mem_thread, seedp, 0, TRUE, FALSE, 0, NULL);
- else
- {
- old_mem_chunks_init();
+ threads = g_alloca (sizeof(GThread*) * n_threads);
+ if (!use_memchunks)
for (i = 0; i < n_threads; i++)
- threads[i] = g_thread_create_full (test_memchunk_thread, seedp, 0, TRUE, FALSE, 0, NULL);
- }
- for (i = 0; i < n_threads; i++)
- g_thread_join (threads[i]);
+ threads[i] = g_thread_create_full (test_sliced_mem_thread, seedp, 0, TRUE, FALSE, 0, NULL);
+ else
+ {
+ old_mem_chunks_init();
+ for (i = 0; i < n_threads; i++)
+ threads[i] = g_thread_create_full (test_memchunk_thread, seedp, 0, TRUE, FALSE, 0, NULL);
+ }
+ for (i = 0; i < n_threads; i++)
+ g_thread_join (threads[i]);
- if (ccounters)
- {
- guint n, n_chunks = g_slice_get_config (G_SLICE_CONFIG_CHUNK_SIZES);
- g_print (" ChunkSize | MagazineSize | Contention\n");
- for (i = 0; i < n_chunks; i++)
- {
- gint64 *vals = g_slice_get_config_state (G_SLICE_CONFIG_CONTENTION_COUNTER, i, &n);
- g_print (" %9llu | %9llu | %9llu\n", vals[0], vals[2], vals[1]);
- g_free (vals);
- }
- }
- else
- g_print ("Done.\n");
- return 0;
+ if (ccounters)
+ {
+ guint n, n_chunks = g_slice_get_config (G_SLICE_CONFIG_CHUNK_SIZES);
+ g_print (" ChunkSize | MagazineSize | Contention\n");
+ for (i = 0; i < n_chunks; i++)
+ {
+ gint64 *vals = g_slice_get_config_state (G_SLICE_CONFIG_CONTENTION_COUNTER, i, &n);
+ g_print (" %9llu | %9llu | %9llu\n", vals[0], vals[2], vals[1]);
+ g_free (vals);
+ }
+ }
+ else
+ g_print ("Done.\n");
+ return 0;
+ }
}