X-Git-Url: https://pd.if.org/git/?p=pdclib.old;a=blobdiff_plain;f=opt%2Fpthreads%2Fmtx_init.c;fp=opt%2Fpthreads%2Fmtx_init.c;h=90c67e62109b0549b2a5f1ee5000c367e66d23ad;hp=0000000000000000000000000000000000000000;hb=d293fb98fe80a472ad4d11b4d8a1413d2142064a;hpb=42ca148113de4800d41cbd0491c508160bb1cf36 diff --git a/opt/pthreads/mtx_init.c b/opt/pthreads/mtx_init.c new file mode 100644 index 0000000..90c67e6 --- /dev/null +++ b/opt/pthreads/mtx_init.c @@ -0,0 +1,44 @@ +#ifndef REGTEST +#include +#include + +int mtx_init(mtx_t *mtx, int type) +{ + if(type == mtx_plain || type == mtx_timed) { + if(pthread_mutex_init(mtx, NULL) == 0) + return thrd_success; + else + return thrd_error; + + } else if (type == mtx_recursive || type == (mtx_recursive | mtx_timed)) { + int rc = thrd_error; + pthread_mutexattr_t attr; + + if(pthread_mutexattr_init(&attr)) + goto cleanup1; + + if(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE)) + goto cleanup2; + + if(pthread_mutex_init(mtx, &attr) == 0) + rc = thrd_success; + + cleanup2: + pthread_mutexattr_destroy(&attr); + cleanup1: + return rc; + } else { + return thrd_error; + } +} +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + return TEST_RESULTS; +} + +#endif