Add a real semaphore implemtation
I've seen races where job N+1 got started before N, this breaks
for dependent jobs. So give up and implement a real semaphore
in mmap'ed shared storage.
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/fio.h b/fio.h
index 7f314de..12cf3c9 100644
--- a/fio.h
+++ b/fio.h
@@ -17,6 +17,7 @@
#include "crc32.h"
#include "arch.h"
#include "os.h"
+#include "mutex.h"
#ifdef FIO_HAVE_SYSLET
#include "syslet.h"
@@ -431,7 +432,7 @@
unsigned long long io_bytes[2];
unsigned long long this_io_bytes[2];
unsigned long long zone_bytes;
- volatile int mutex;
+ struct fio_sem *mutex;
/*
* State for random io, a bitmap of blocks done vs not done
@@ -704,30 +705,6 @@
extern void td_io_close_file(struct thread_data *, struct fio_file *);
/*
- * This is a pretty crappy semaphore implementation, but with the use that fio
- * has (just signalling start/go conditions), it doesn't have to be better.
- * Naturally this would not work for any type of contended semaphore or
- * for real locking.
- */
-static inline void fio_sem_init(volatile int *sem, int val)
-{
- *sem = val;
-}
-
-static inline void fio_sem_down(volatile int *sem)
-{
- while (*sem == 0)
- usleep(10000);
-
- (*sem)--;
-}
-
-static inline void fio_sem_up(volatile int *sem)
-{
- (*sem)++;
-}
-
-/*
* If logging output to a file, stderr should go to both stderr and f_err
*/
#define log_err(args...) do { \