]> pd.if.org Git - pdclib/blobdiff - opt/nothread/call_once.c
* Test cleanups: surround the code for all functions by #ifndef REGTEST
[pdclib] / opt / nothread / call_once.c
index 06de779568c390294955d1c4010f50b188717604..83201708b401fecc38e8a3bb0ffad8df89a99014 100644 (file)
@@ -1,3 +1,4 @@
+#ifndef REGTEST\r
 #include <threads.h>\r
 \r
 void _PDCLIB_call_once(_PDCLIB_once_flag *flag, void (*func)(void))\r
@@ -6,4 +7,34 @@ void _PDCLIB_call_once(_PDCLIB_once_flag *flag, void (*func)(void))
                func();\r
                *flag = _PDCLIB_ONCE_FLAG_DONE;\r
        }\r
-}
\ No newline at end of file
+}\r
+#endif\r
+\r
+#ifdef TEST\r
+#include <_PDCLIB_test.h>\r
+\r
+#ifndef REGTEST\r
+static int count = 0;\r
+static once_flag once = ONCE_FLAG_INIT;\r
+\r
+static void do_once(void)\r
+{\r
+    count++;\r
+}\r
+#endif\r
+\r
+int main( void )\r
+{\r
+#ifndef REGTEST\r
+    TESTCASE(count == 0);\r
+    call_once(&once, do_once);\r
+    TESTCASE(count == 1);\r
+    call_once(&once, do_once);\r
+    TESTCASE(count == 1);\r
+    do_once();\r
+    TESTCASE(count == 2);\r
+#endif\r
+    return TEST_RESULTS;\r
+}\r
+\r
+#endif\r