X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=opt%2Fpthreads%2Fcall_once.c;fp=opt%2Fpthreads%2Fcall_once.c;h=123ad3a91b1ba636a40888849ce295d0d2bbfbe2;hb=a3b310f13d9001554fe24f3eebab8c0bebac72ca;hp=0000000000000000000000000000000000000000;hpb=c2d0eabd70beb268554939e4cc7fdc0732b21141;p=pdclib diff --git a/opt/pthreads/call_once.c b/opt/pthreads/call_once.c new file mode 100644 index 0000000..123ad3a --- /dev/null +++ b/opt/pthreads/call_once.c @@ -0,0 +1,38 @@ +#ifndef REGTEST +#include +#include + +void call_once(once_flag *flag, void (*func)(void)) +{ + pthread_once(flag, func); +} +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +#ifndef REGTEST +static int count = 0; +static once_flag once = ONCE_FLAG_INIT; + +static void do_once(void) +{ + count++; +} +#endif + +int main( void ) +{ +#ifndef REGTEST + TESTCASE(count == 0); + call_once(&once, do_once); + TESTCASE(count == 1); + call_once(&once, do_once); + TESTCASE(count == 1); + do_once(); + TESTCASE(count == 2); +#endif + return TEST_RESULTS; +} + +#endif