X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=mutex.c;h=c1ce2a3e8740de808e70076a141b642646f9087f;hp=a44743745ab43d18b8342a67598b4977c1e43557;hb=03e20d687566753b90383571e5e152c5142bdffd;hpb=656b1393d43f9f22738404582ea14dec956aea83;ds=sidebyside diff --git a/mutex.c b/mutex.c index a4474374..c1ce2a3e 100644 --- a/mutex.c +++ b/mutex.c @@ -11,6 +11,7 @@ #include "mutex.h" #include "arch/arch.h" #include "os/os.h" +#include "helpers.h" void fio_mutex_remove(struct fio_mutex *mutex) { @@ -32,6 +33,14 @@ struct fio_mutex *fio_mutex_init(int value) return NULL; } +#ifdef FIO_HAVE_FALLOCATE + ret = posix_fallocate(fd, 0, sizeof(struct fio_mutex)); + if (ret > 0) { + fprintf(stderr, "posix_fallocate mutex failed: %s\n", strerror(ret)); + goto err; + } +#endif + if (ftruncate(fd, sizeof(struct fio_mutex)) < 0) { perror("ftruncate mutex"); goto err; @@ -64,14 +73,18 @@ struct fio_mutex *fio_mutex_init(int value) log_err("pthread_mutexattr_init: %s\n", strerror(ret)); goto err; } +#ifdef FIO_HAVE_PSHARED_MUTEX ret = pthread_mutexattr_setpshared(&attr, mflag); if (ret) { log_err("pthread_mutexattr_setpshared: %s\n", strerror(ret)); goto err; } +#endif pthread_condattr_init(&cond); +#ifdef FIO_HAVE_PSHARED_MUTEX pthread_condattr_setpshared(&cond, mflag); +#endif pthread_cond_init(&mutex->cond, &cond); ret = pthread_mutex_init(&mutex->lock, &attr); @@ -80,6 +93,9 @@ struct fio_mutex *fio_mutex_init(int value) goto err; } + pthread_condattr_destroy(&cond); + pthread_mutexattr_destroy(&attr); + return mutex; err: if (mutex)