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