To be used by the file sharing.
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
PROGS = fio
SCRIPTS = fio_generate_plots
OBJS = gettime.o fio.o ioengines.o init.o stat.o log.o time.o filesetup.o \
- eta.o verify.o memory.o io_u.o parse.o mutex.o options.o rbtree.o \
- diskutil.o fifo.o blktrace.o smalloc.o
+ eta.o verify.o memory.o io_u.o parse.o mutex.o sem.o options.o \
+ rbtree.o diskutil.o fifo.o blktrace.o smalloc.o
OBJS += crc/crc7.o
OBJS += crc/crc16.o
--- /dev/null
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <sys/mman.h>
+#include <assert.h>
+
+#include "sem.h"
+#include "smalloc.h"
+
+void fio_sem_remove(struct fio_sem *sem)
+{
+ sfree(sem);
+}
+
+struct fio_sem *fio_sem_init(int value)
+{
+ struct fio_sem *sem;
+
+ sem = smalloc(sizeof(*sem));
+ if (!sem)
+ return NULL;
+
+ sem->sem_val = value;
+
+ if (!sem_init(&sem->sem, 1, value))
+ return sem;
+
+ perror("sem_init");
+ sfree(sem);
+ return NULL;
+}
+
+void fio_sem_down(struct fio_sem *sem)
+{
+ sem_wait(&sem->sem);
+}
+
+void fio_sem_up(struct fio_sem *sem)
+{
+ sem_post(&sem->sem);
+}
--- /dev/null
+#ifndef FIO_SEM_H
+#define FIO_SEM_H
+
+#include <semaphore.h>
+
+struct fio_sem {
+ sem_t sem;
+ int sem_val;
+};
+
+extern struct fio_sem *fio_sem_init(int);
+extern void fio_sem_remove(struct fio_sem *);
+extern void fio_sem_down(struct fio_sem *);
+extern void fio_sem_up(struct fio_sem *);
+
+#endif