X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=opt%2Fpthreads%2Fmtx_init.c;fp=opt%2Fpthreads%2Fmtx_init.c;h=90c67e62109b0549b2a5f1ee5000c367e66d23ad;hb=a3b310f13d9001554fe24f3eebab8c0bebac72ca;hp=0000000000000000000000000000000000000000;hpb=c2d0eabd70beb268554939e4cc7fdc0732b21141;p=pdclib 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