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