X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=pshared.c;h=182a36529df70acbd9b254a00444c2eacc02c2c6;hb=b6b64bfec2dd4ce7db64c57ecf771bb7b2f105f6;hp=74812ede35ecc0ecf51f09b9c3a444ca4563110c;hpb=ae626d4ead6416adf464cf209cdf3e8b85d58190;p=fio.git diff --git a/pshared.c b/pshared.c index 74812ede..182a3652 100644 --- a/pshared.c +++ b/pshared.c @@ -21,6 +21,15 @@ int cond_init_pshared(pthread_cond_t *cond) return ret; } #endif + +#ifdef CONFIG_PTHREAD_CONDATTR_SETCLOCK + ret = pthread_condattr_setclock(&cattr, CLOCK_MONOTONIC); + if (ret) { + log_err("pthread_condattr_setclock: %s\n", strerror(ret)); + return ret; + } +#endif + ret = pthread_cond_init(cond, &cattr); if (ret) { log_err("pthread_cond_init: %s\n", strerror(ret)); @@ -30,7 +39,11 @@ int cond_init_pshared(pthread_cond_t *cond) return 0; } -int mutex_init_pshared(pthread_mutex_t *mutex) +/* + * '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; int ret; @@ -42,7 +55,7 @@ int mutex_init_pshared(pthread_mutex_t *mutex) } /* - * 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); @@ -51,15 +64,26 @@ int mutex_init_pshared(pthread_mutex_t *mutex) return ret; } #endif + 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, PTHREAD_MUTEX_DEFAULT); +} + int mutex_cond_init_pshared(pthread_mutex_t *mutex, pthread_cond_t *cond) { int ret;