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