7701a24f7777efcc47a249abd27746d4241b1ccb
[platform/upstream/fontconfig.git] / test / test-pthread.c
1 /* Code originally from Raimund Steger. */
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <pthread.h>
7 #include <fontconfig/fontconfig.h>
8
9 #define NTHR 100
10 #define NTEST 100
11
12 struct thr_arg_s
13 {
14         int thr_num;
15 };
16
17 static void test_match(int thr_num,int test_num)
18 {
19         FcPattern *pat;
20         FcPattern *match;
21         FcResult  result;
22
23         FcInit();
24
25         pat = FcNameParse((const FcChar8 *)"New Century Schoolbook");
26                 
27         FcConfigSubstitute(0,pat,FcMatchPattern);
28         FcDefaultSubstitute(pat);
29         
30         match = FcFontMatch(0,pat,&result);
31                 
32         FcPatternDestroy(pat);
33         FcPatternDestroy(match);
34 }
35
36 static void *run_test_in_thread(void *arg)
37 {
38         struct thr_arg_s *thr_arg=(struct thr_arg_s *)arg;
39         int thread_num = thr_arg->thr_num;
40         int i=0;
41
42         for(;i<NTEST;i++) test_match(thread_num,i);
43
44         printf("Thread %d: done\n",thread_num);
45
46         return NULL;
47 }
48
49 int main(int argc,char **argv)
50 {
51         pthread_t threads[NTHR];
52         int i, j;
53
54         printf("Creating %d threads\n",NTHR);
55
56         for(i = 0;i<NTHR;i++)
57         {
58                 struct thr_arg_s thr_arg;
59                 int result;
60                 thr_arg.thr_num=i;
61                 result = pthread_create(&threads[i],NULL,run_test_in_thread,
62                                         (void *)&thr_arg);
63                 if(result!=0)
64                 {
65                         fprintf(stderr,"Cannot create thread %d\n",i);
66                         break;
67                 }
68         }
69
70         for(j=0;j<i;j++)
71         {
72                 pthread_join(threads[j],NULL);
73                 printf("Joined thread %d\n",j);
74         }
75
76         FcFini();
77
78         return 0;
79 }