fio: fix dlopen refcounting of dynamic engines
[fio.git] / fio_sem.c
index 20fcfccc02eea36c3d6d32cd442d47f34b1bbe95..c7806acb26ae3ea51211e5488819ce24add451db 100644 (file)
--- a/fio_sem.c
+++ b/fio_sem.c
@@ -1,3 +1,4 @@
+#include <stdio.h>
 #include <string.h>
 #include <sys/mman.h>
 #include <assert.h>
@@ -7,7 +8,6 @@
 #define RUNNING_ON_VALGRIND 0
 #endif
 
-#include "log.h"
 #include "fio_sem.h"
 #include "pshared.h"
 #include "os/os.h"
@@ -85,16 +85,19 @@ static bool sem_timed_out(struct timespec *t, unsigned int msecs)
 
 int fio_sem_down_timeout(struct fio_sem *sem, unsigned int msecs)
 {
-       struct timeval tv_s;
        struct timespec base;
        struct timespec t;
        int ret = 0;
 
        assert(sem->magic == FIO_SEM_MAGIC);
 
-       gettimeofday(&tv_s, NULL);
-       base.tv_sec = t.tv_sec = tv_s.tv_sec;
-       base.tv_nsec = t.tv_nsec = tv_s.tv_usec * 1000;
+#ifdef CONFIG_PTHREAD_CONDATTR_SETCLOCK
+       clock_gettime(CLOCK_MONOTONIC, &t);
+#else
+       clock_gettime(CLOCK_REALTIME, &t);
+#endif
+
+       base = t;
 
        t.tv_sec += msecs / 1000;
        t.tv_nsec += ((msecs * 1000000ULL) % 1000000000);
@@ -166,7 +169,6 @@ void fio_sem_up(struct fio_sem *sem)
        assert(sem->magic == FIO_SEM_MAGIC);
 
        pthread_mutex_lock(&sem->lock);
-       read_barrier();
        if (!sem->value && sem->waiters)
                do_wake = 1;
        sem->value++;