[PATCH] Compile and works on OpenSolaris (tested on BeleniX)
[fio.git] / fio.c
diff --git a/fio.c b/fio.c
index 09c960fd672385219c04cf8557682fa7129554fc..1248971aca2a75da0fc32074898312ebe0895696 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -63,7 +63,7 @@ enum {
 
 #define should_fsync(td)       ((td_write(td) || td_rw(td)) && (!(td)->odirect || (td)->override_sync))
 
-static sem_t startup_sem;
+static volatile int startup_sem;
 
 #define TERMINATE_ALL          (-1)
 #define JOB_START_TIMEOUT      (5 * 1000)
@@ -360,11 +360,11 @@ static int get_rw_ddir(struct thread_data *td)
                 * Check if it's time to seed a new data direction.
                 */
                if (elapsed >= td->rwmixcycle) {
-                       unsigned long v;
+                       int v;
                        long r;
 
-                       r = os_random_long(&td->random_state);
-                       v = 100UL * r / (unsigned long) (RAND_MAX + 1.0);
+                       r = os_random_long(&td->rwmix_state);
+                       v = 1 + (int) (100.0 * (r / (RAND_MAX + 1.0)));
                        if (v < td->rwmixread)
                                td->rwmix_ddir = DDIR_READ;
                        else
@@ -933,22 +933,6 @@ static int init_io_u(struct thread_data *td)
        return 0;
 }
 
-static void cleanup_allocs(struct thread_data *td)
-{
-       if (td->directory)
-               free(td->directory);
-       if (td->iolog_file)
-               free(td->iolog_file);
-       if (td->exec_prerun)
-               free(td->exec_prerun);
-       if (td->exec_postrun)
-               free(td->exec_postrun);
-       if (td->ioscheduler)
-               free(td->ioscheduler);
-       if (td->sysfs_root)
-               free(td->sysfs_root);
-}
-
 static int create_file(struct thread_data *td, unsigned long long size,
                       int extend)
 {
@@ -1189,7 +1173,7 @@ static int setup_file(struct thread_data *td)
        }
 
        if (td->odirect)
-               flags |= O_DIRECT;
+               flags |= OS_O_DIRECT;
 
        if (td_write(td) || td_rw(td)) {
                if (td->filetype == FIO_TYPE_FILE) {
@@ -1336,8 +1320,8 @@ static void *thread_main(void *data)
                goto err;
 
        td_set_runstate(td, TD_INITIALIZED);
-       sem_post(&startup_sem);
-       sem_wait(&td->mutex);
+       fio_sem_up(&startup_sem);
+       fio_sem_down(&td->mutex);
 
        if (!td->create_serialize && setup_file(td))
                goto err;
@@ -1404,7 +1388,6 @@ err:
        }
        if (td->mmap)
                munmap(td->mmap, td->file_size);
-       cleanup_allocs(td);
        cleanup_io(td);
        cleanup_io_u(td);
        td_set_runstate(td, TD_EXITED);
@@ -1788,7 +1771,7 @@ static void run_threads(void)
                         */
                        td_set_runstate(td, TD_CREATED);
                        map[this_jobs++] = td;
-                       sem_init(&startup_sem, 0, 1);
+                       fio_sem_init(&startup_sem, 1);
                        nr_started++;
 
                        if (td->use_thread) {
@@ -1798,7 +1781,7 @@ static void run_threads(void)
                                }
                        } else {
                                if (fork())
-                                       sem_wait(&startup_sem);
+                                       fio_sem_down(&startup_sem);
                                else {
                                        fork_main(shm_id, i);
                                        exit(0);
@@ -1862,7 +1845,7 @@ static void run_threads(void)
                        m_rate += td->ratemin;
                        t_rate += td->rate;
                        todo--;
-                       sem_post(&td->mutex);
+                       fio_sem_up(&td->mutex);
                }
 
                reap_threads(&nr_running, &t_rate, &m_rate);