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