1/* 2 * fontconfig/test/test-pthread.c 3 * 4 * Copyright © 2000 Keith Packard 5 * Copyright © 2013 Raimund Steger 6 * 7 * Permission to use, copy, modify, distribute, and sell this software and its 8 * documentation for any purpose is hereby granted without fee, provided that 9 * the above copyright notice appear in all copies and that both that 10 * copyright notice and this permission notice appear in supporting 11 * documentation, and that the name of the author(s) not be used in 12 * advertising or publicity pertaining to distribution of the software without 13 * specific, written prior permission. The authors make no 14 * representations about the suitability of this software for any purpose. It 15 * is provided "as is" without express or implied warranty. 16 * 17 * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 18 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 19 * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR 20 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 21 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 22 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 23 * PERFORMANCE OF THIS SOFTWARE. 24 */ 25#include <stdio.h> 26#include <stdlib.h> 27#include <unistd.h> 28#include <pthread.h> 29#include <fontconfig/fontconfig.h> 30 31#define NTHR 100 32#define NTEST 100 33 34struct thr_arg_s 35{ 36 int thr_num; 37}; 38 39static void test_match(int thr_num,int test_num) 40{ 41 FcPattern *pat; 42 FcPattern *match; 43 FcResult result; 44 45 FcInit(); 46 47 pat = FcNameParse((const FcChar8 *)"New Century Schoolbook"); 48 49 FcConfigSubstitute(0,pat,FcMatchPattern); 50 FcDefaultSubstitute(pat); 51 52 match = FcFontMatch(0,pat,&result); 53 54 FcPatternDestroy(pat); 55 FcPatternDestroy(match); 56} 57 58static void *run_test_in_thread(void *arg) 59{ 60 struct thr_arg_s *thr_arg=(struct thr_arg_s *)arg; 61 int thread_num = thr_arg->thr_num; 62 int i=0; 63 64 for(;i<NTEST;i++) test_match(thread_num,i); 65 66 printf("Thread %d: done\n",thread_num); 67 68 return NULL; 69} 70 71int main(int argc,char **argv) 72{ 73 pthread_t threads[NTHR]; 74 struct thr_arg_s thr_args[NTHR]; 75 int i, j; 76 77 printf("Creating %d threads\n",NTHR); 78 79 for(i = 0;i<NTHR;i++) 80 { 81 int result; 82 thr_args[i].thr_num=i; 83 result = pthread_create(&threads[i],NULL,run_test_in_thread, 84 (void *)&thr_args[i]); 85 if(result!=0) 86 { 87 fprintf(stderr,"Cannot create thread %d\n",i); 88 break; 89 } 90 } 91 92 for(j=0;j<i;j++) 93 { 94 pthread_join(threads[j],NULL); 95 printf("Joined thread %d\n",j); 96 } 97 98 FcFini(); 99 100 return 0; 101} 102