Convert %lld and %llu in printf formats to G_G[U]INT64_FORMAT. Fix pointer<->int...
[platform/upstream/gstreamer.git] / tests / memchunk / gmemchunktest.c
1 #include <gst/gst.h>
2 #include <string.h>             /* strerror */
3
4 #define MAX_THREADS  100
5
6 static GMemChunk *_chunks;
7 static GMutex *_lock;
8
9 static gint num_allocs;
10 static gint num_threads;
11
12 static gpointer 
13 alloc_chunk (void)
14 {
15   gpointer ret;
16   g_mutex_lock (_lock); 
17   ret = g_mem_chunk_alloc (_chunks);
18   g_mutex_unlock (_lock); 
19
20   return ret;
21 }
22
23 static void 
24 free_chunk (gpointer chunk)
25 {
26   g_mutex_lock (_lock); 
27   g_mem_chunk_free (_chunks, chunk);
28   g_mutex_unlock (_lock); 
29 }
30
31
32 void*
33 run_test (void *threadid)
34 {
35   gint i;
36   gpointer chunk;
37   sleep(1);
38
39   for (i = 0; i<num_allocs; i++) {
40     chunk = alloc_chunk ();
41     free_chunk (chunk);
42   }
43
44   g_thread_exit(NULL);
45   return NULL;
46 }
47
48
49 gint 
50 main (gint argc, gchar *argv[]) 
51 {
52   GThread *threads[MAX_THREADS];
53   GError *error;
54   int t;
55  
56   gst_init (&argc, &argv);
57
58   if (argc != 3) {
59     g_print ("usage: %s <num_threads> <num_allocs>\n", argv[0]);
60     exit (-1);
61   }
62
63   num_threads = atoi (argv[1]);
64   num_allocs = atoi (argv[2]);
65
66   _chunks = g_mem_chunk_new ("test", 32, 32 * 16, G_ALLOC_AND_FREE);
67   _lock = g_mutex_new ();
68
69   for(t=0; t < num_threads; t++) {
70     error = NULL;
71     threads[t] = g_thread_create (run_test, GINT_TO_POINTER(t), TRUE, &error);
72     if (error) {
73       printf ("ERROR: g_thread_create () is %s\n", error->message);
74       exit (-1);
75     }
76   }
77   printf ("main(): Created %d threads.\n", t);
78
79   g_thread_exit (NULL);
80   g_mem_chunk_info();
81   return 0;
82 }