]> pd.if.org Git - pdclib/blob - opt/pthreads/call_once.c
PDCLib includes with quotes, not <>.
[pdclib] / opt / pthreads / call_once.c
1 #ifndef REGTEST
2 #include <threads.h>
3 #include <pthread.h>
4
5 void call_once(once_flag *flag, void (*func)(void))
6 {
7     pthread_once(flag, func);
8 }
9 #endif
10
11 #ifdef TEST
12 #include "_PDCLIB_test.h"
13
14 #ifndef REGTEST
15 static int count = 0;
16 static once_flag once = ONCE_FLAG_INIT;
17
18 static void do_once(void)
19 {
20     count++;
21 }
22 #endif
23
24 int main( void )
25 {
26 #ifndef REGTEST
27     TESTCASE(count == 0);
28     call_once(&once, do_once);
29     TESTCASE(count == 1);
30     call_once(&once, do_once);
31     TESTCASE(count == 1);
32     do_once();
33     TESTCASE(count == 2);
34 #endif
35     return TEST_RESULTS;
36 }
37
38 #endif