X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=pshared.c;h=182a36529df70acbd9b254a00444c2eacc02c2c6;hb=dc8a3d629310d1ac9143d62c9f37ff16331737d5;hp=791faf95e9569732af1fe05a7ad393c50d57ed6a;hpb=3ed6894b00c4929896ff169778cf05752e2ed825;p=fio.git diff --git a/pshared.c b/pshared.c index 791faf95..182a3652 100644 --- a/pshared.c +++ b/pshared.c @@ -39,6 +39,10 @@ int cond_init_pshared(pthread_cond_t *cond) return 0; } +/* + * 'type' must be a mutex type, e.g. PTHREAD_MUTEX_NORMAL, + * PTHREAD_MUTEX_ERRORCHECK, PTHREAD_MUTEX_RECURSIVE or PTHREAD_MUTEX_DEFAULT. + */ int mutex_init_pshared_with_type(pthread_mutex_t *mutex, int type) { pthread_mutexattr_t mattr; @@ -51,7 +55,7 @@ int mutex_init_pshared_with_type(pthread_mutex_t *mutex, int type) } /* - * Not all platforms support process shared mutexes (FreeBSD) + * Not all platforms support process shared mutexes (NetBSD/OpenBSD) */ #ifdef CONFIG_PSHARED ret = pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED); @@ -60,26 +64,24 @@ int mutex_init_pshared_with_type(pthread_mutex_t *mutex, int type) return ret; } #endif - if (type) { - ret = pthread_mutexattr_settype(&mattr, type); - if (ret) { - log_err("pthread_mutexattr_settype: %s\n", - strerror(ret)); - return ret; - } + ret = pthread_mutexattr_settype(&mattr, type); + if (ret) { + log_err("pthread_mutexattr_settype: %s\n", strerror(ret)); + return ret; } ret = pthread_mutex_init(mutex, &mattr); if (ret) { log_err("pthread_mutex_init: %s\n", strerror(ret)); return ret; } + pthread_mutexattr_destroy(&mattr); return 0; } int mutex_init_pshared(pthread_mutex_t *mutex) { - return mutex_init_pshared_with_type(mutex, 0); + return mutex_init_pshared_with_type(mutex, PTHREAD_MUTEX_DEFAULT); } int mutex_cond_init_pshared(pthread_mutex_t *mutex, pthread_cond_t *cond)