projects
/
fio.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
A few HP-UX fixes
[fio.git]
/
mutex.c
diff --git
a/mutex.c
b/mutex.c
index a44743745ab43d18b8342a67598b4977c1e43557..bbbcccbd0587a7139b247ac4eb38350337fcd912 100644
(file)
--- a/
mutex.c
+++ b/
mutex.c
@@
-11,43
+11,29
@@
#include "mutex.h"
#include "arch/arch.h"
#include "os/os.h"
#include "mutex.h"
#include "arch/arch.h"
#include "os/os.h"
+#include "helpers.h"
void fio_mutex_remove(struct fio_mutex *mutex)
{
void fio_mutex_remove(struct fio_mutex *mutex)
{
- close(mutex->mutex_fd);
munmap((void *) mutex, sizeof(*mutex));
}
struct fio_mutex *fio_mutex_init(int value)
{
munmap((void *) mutex, sizeof(*mutex));
}
struct fio_mutex *fio_mutex_init(int value)
{
- char mutex_name[] = "/tmp/.fio_mutex.XXXXXX";
struct fio_mutex *mutex = NULL;
pthread_mutexattr_t attr;
pthread_condattr_t cond;
struct fio_mutex *mutex = NULL;
pthread_mutexattr_t attr;
pthread_condattr_t cond;
- int fd, ret, mflag;
-
- fd = mkstemp(mutex_name);
- if (fd < 0) {
- perror("open mutex");
- return NULL;
- }
-
- if (ftruncate(fd, sizeof(struct fio_mutex)) < 0) {
- perror("ftruncate mutex");
- goto err;
- }
+ int ret, mflag;
mutex = (void *) mmap(NULL, sizeof(struct fio_mutex),
mutex = (void *) mmap(NULL, sizeof(struct fio_mutex),
- PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+ PROT_READ | PROT_WRITE,
+ OS_MAP_ANON | MAP_SHARED, -1, 0);
if (mutex == MAP_FAILED) {
perror("mmap mutex");
if (mutex == MAP_FAILED) {
perror("mmap mutex");
- close(fd);
mutex = NULL;
goto err;
}
mutex = NULL;
goto err;
}
- unlink(mutex_name);
- mutex->mutex_fd = fd;
mutex->value = value;
/*
mutex->value = value;
/*
@@
-64,14
+50,18
@@
struct fio_mutex *fio_mutex_init(int value)
log_err("pthread_mutexattr_init: %s\n", strerror(ret));
goto err;
}
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;
}
ret = pthread_mutexattr_setpshared(&attr, mflag);
if (ret) {
log_err("pthread_mutexattr_setpshared: %s\n", strerror(ret));
goto err;
}
+#endif
pthread_condattr_init(&cond);
pthread_condattr_init(&cond);
+#ifdef FIO_HAVE_PSHARED_MUTEX
pthread_condattr_setpshared(&cond, mflag);
pthread_condattr_setpshared(&cond, mflag);
+#endif
pthread_cond_init(&mutex->cond, &cond);
ret = pthread_mutex_init(&mutex->lock, &attr);
pthread_cond_init(&mutex->cond, &cond);
ret = pthread_mutex_init(&mutex->lock, &attr);
@@
-80,12
+70,14
@@
struct fio_mutex *fio_mutex_init(int value)
goto err;
}
goto err;
}
+ pthread_condattr_destroy(&cond);
+ pthread_mutexattr_destroy(&attr);
+
return mutex;
err:
if (mutex)
fio_mutex_remove(mutex);
return mutex;
err:
if (mutex)
fio_mutex_remove(mutex);
- unlink(mutex_name);
return NULL;
}
return NULL;
}