Move tp.[ch] to lib/
authorJens Axboe <axboe@fb.com>
Thu, 3 Jul 2014 20:16:25 +0000 (14:16 -0600)
committerJens Axboe <axboe@fb.com>
Thu, 3 Jul 2014 20:16:25 +0000 (14:16 -0600)
It's just helper code, not fio core.

Signed-off-by: Jens Axboe <axboe@fb.com>
Makefile
backend.c
iolog.c
lib/tp.c [new file with mode: 0644]
lib/tp.h [new file with mode: 0644]
tp.c [deleted file]
tp.h [deleted file]

index f179b644c37ae81d094b79ce25343052c892bfb6..65e95be6c9f4a5a485075e09eccea7033c62356e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -36,7 +36,7 @@ SOURCE := gettime.c ioengines.c init.c stat.c log.c time.c filesetup.c \
                lib/lfsr.c gettime-thread.c helpers.c lib/flist_sort.c \
                lib/hweight.c lib/getrusage.c idletime.c td_error.c \
                profiles/tiobench.c profiles/act.c io_u_queue.c filelock.c \
                lib/lfsr.c gettime-thread.c helpers.c lib/flist_sort.c \
                lib/hweight.c lib/getrusage.c idletime.c td_error.c \
                profiles/tiobench.c profiles/act.c io_u_queue.c filelock.c \
-               tp.c
+               lib/tp.c
 
 ifdef CONFIG_64BIT_LLP64
   CFLAGS += -DBITS_PER_LONG=32
 
 ifdef CONFIG_64BIT_LLP64
   CFLAGS += -DBITS_PER_LONG=32
index e32d84165273cb5c71fc520d4926b2afd1708a18..68540abb9a2c1bd80c346d311f94646b464e2ff9 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -53,7 +53,7 @@
 #include "lib/getrusage.h"
 #include "idletime.h"
 #include "err.h"
 #include "lib/getrusage.h"
 #include "idletime.h"
 #include "err.h"
-#include "tp.h"
+#include "lib/tp.h"
 
 static pthread_t disk_util_thread;
 static struct fio_mutex *disk_thread_mutex;
 
 static pthread_t disk_util_thread;
 static struct fio_mutex *disk_thread_mutex;
diff --git a/iolog.c b/iolog.c
index 0d07b0e3170752a100dd148ba79dad1fe50a74f2..950670562f61045a4256adc28ca23ccdaed4821c 100644 (file)
--- a/iolog.c
+++ b/iolog.c
@@ -18,7 +18,7 @@
 #include "verify.h"
 #include "trim.h"
 #include "filelock.h"
 #include "verify.h"
 #include "trim.h"
 #include "filelock.h"
-#include "tp.h"
+#include "lib/tp.h"
 
 static const char iolog_ver2[] = "fio version 2 iolog";
 
 
 static const char iolog_ver2[] = "fio version 2 iolog";
 
diff --git a/lib/tp.c b/lib/tp.c
new file mode 100644 (file)
index 0000000..25f7eb6
--- /dev/null
+++ b/lib/tp.c
@@ -0,0 +1,101 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <errno.h>
+#include <pthread.h>
+
+#include "../smalloc.h"
+#include "../log.h"
+#include "tp.h"
+
+static void tp_flush_work(struct flist_head *list)
+{
+       struct tp_work *work;
+
+       while (!flist_empty(list)) {
+               work = flist_entry(list->next, struct tp_work, list);
+               flist_del(&work->list);
+               work->fn(work);
+       }
+}
+
+static void *tp_thread(void *data)
+{
+       struct tp_data *tdat = data;
+       struct flist_head work_list;
+
+       INIT_FLIST_HEAD(&work_list);
+
+       while (1) {
+               pthread_mutex_lock(&tdat->lock);
+
+               if (!tdat->thread_exit && flist_empty(&tdat->work))
+                       pthread_cond_wait(&tdat->cv, &tdat->lock);
+
+               if (!flist_empty(&tdat->work)) {
+                       flist_splice(&tdat->work, &work_list);
+                       INIT_FLIST_HEAD(&tdat->work);
+               }
+
+               pthread_mutex_unlock(&tdat->lock);
+
+               if (flist_empty(&work_list)) {
+                       if (tdat->thread_exit)
+                               break;
+                       continue;
+               }
+
+               tp_flush_work(&work_list);
+       }
+
+       return NULL;
+}
+
+void tp_queue_work(struct tp_data *tdat, struct tp_work *work)
+{
+       work->done = 0;
+
+       pthread_mutex_lock(&tdat->lock);
+       flist_add_tail(&work->list, &tdat->work);
+       pthread_cond_signal(&tdat->cv);
+       pthread_mutex_unlock(&tdat->lock);
+}
+
+void tp_init(struct tp_data **tdatp)
+{
+       struct tp_data *tdat;
+       int ret;
+
+       if (*tdatp)
+               return;
+
+       *tdatp = tdat = smalloc(sizeof(*tdat));
+       pthread_mutex_init(&tdat->lock, NULL);
+       INIT_FLIST_HEAD(&tdat->work);
+       pthread_cond_init(&tdat->cv, NULL);
+       pthread_cond_init(&tdat->sleep_cv, NULL);
+
+       ret = pthread_create(&tdat->thread, NULL, tp_thread, tdat);
+       if (ret)
+               log_err("fio: failed to create tp thread\n");
+}
+
+void tp_exit(struct tp_data **tdatp)
+{
+       struct tp_data *tdat = *tdatp;
+       void *ret;
+
+       if (!tdat)
+               return;
+
+       tdat->thread_exit = 1;
+       pthread_mutex_lock(&tdat->lock);
+       pthread_cond_signal(&tdat->cv);
+       pthread_mutex_unlock(&tdat->lock);
+
+       pthread_join(tdat->thread, &ret);
+
+       sfree(tdat);
+       *tdatp = NULL;
+}
diff --git a/lib/tp.h b/lib/tp.h
new file mode 100644 (file)
index 0000000..5b07cc6
--- /dev/null
+++ b/lib/tp.h
@@ -0,0 +1,32 @@
+#ifndef FIO_TP_H
+#define FIO_TP_H
+
+#include "../flist.h"
+
+struct tp_work;
+typedef int (tp_work_fn)(struct tp_work *);
+
+struct tp_work {
+       struct flist_head list;
+       tp_work_fn *fn;
+       int wait;
+       pthread_cond_t cv;
+       pthread_mutex_t lock;
+       volatile int done;
+};
+
+struct tp_data {
+       pthread_t thread;
+       pthread_cond_t cv;
+       pthread_mutex_t lock;
+       struct flist_head work;
+       volatile int thread_exit;
+       pthread_cond_t sleep_cv;
+       volatile int sleeping;
+};
+
+extern void tp_init(struct tp_data **);
+extern void tp_exit(struct tp_data **);
+extern void tp_queue_work(struct tp_data *, struct tp_work *);
+
+#endif
diff --git a/tp.c b/tp.c
deleted file mode 100644 (file)
index 81d17b6..0000000
--- a/tp.c
+++ /dev/null
@@ -1,101 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <unistd.h>
-#include <errno.h>
-#include <pthread.h>
-
-#include "smalloc.h"
-#include "log.h"
-#include "tp.h"
-
-static void tp_flush_work(struct flist_head *list)
-{
-       struct tp_work *work;
-
-       while (!flist_empty(list)) {
-               work = flist_entry(list->next, struct tp_work, list);
-               flist_del(&work->list);
-               work->fn(work);
-       }
-}
-
-static void *tp_thread(void *data)
-{
-       struct tp_data *tdat = data;
-       struct flist_head work_list;
-
-       INIT_FLIST_HEAD(&work_list);
-
-       while (1) {
-               pthread_mutex_lock(&tdat->lock);
-
-               if (!tdat->thread_exit && flist_empty(&tdat->work))
-                       pthread_cond_wait(&tdat->cv, &tdat->lock);
-
-               if (!flist_empty(&tdat->work)) {
-                       flist_splice(&tdat->work, &work_list);
-                       INIT_FLIST_HEAD(&tdat->work);
-               }
-
-               pthread_mutex_unlock(&tdat->lock);
-
-               if (flist_empty(&work_list)) {
-                       if (tdat->thread_exit)
-                               break;
-                       continue;
-               }
-
-               tp_flush_work(&work_list);
-       }
-
-       return NULL;
-}
-
-void tp_queue_work(struct tp_data *tdat, struct tp_work *work)
-{
-       work->done = 0;
-
-       pthread_mutex_lock(&tdat->lock);
-       flist_add_tail(&work->list, &tdat->work);
-       pthread_cond_signal(&tdat->cv);
-       pthread_mutex_unlock(&tdat->lock);
-}
-
-void tp_init(struct tp_data **tdatp)
-{
-       struct tp_data *tdat;
-       int ret;
-
-       if (*tdatp)
-               return;
-
-       *tdatp = tdat = smalloc(sizeof(*tdat));
-       pthread_mutex_init(&tdat->lock, NULL);
-       INIT_FLIST_HEAD(&tdat->work);
-       pthread_cond_init(&tdat->cv, NULL);
-       pthread_cond_init(&tdat->sleep_cv, NULL);
-
-       ret = pthread_create(&tdat->thread, NULL, tp_thread, tdat);
-       if (ret)
-               log_err("fio: failed to create tp thread\n");
-}
-
-void tp_exit(struct tp_data **tdatp)
-{
-       struct tp_data *tdat = *tdatp;
-       void *ret;
-
-       if (!tdat)
-               return;
-
-       tdat->thread_exit = 1;
-       pthread_mutex_lock(&tdat->lock);
-       pthread_cond_signal(&tdat->cv);
-       pthread_mutex_unlock(&tdat->lock);
-
-       pthread_join(tdat->thread, &ret);
-
-       sfree(tdat);
-       *tdatp = NULL;
-}
diff --git a/tp.h b/tp.h
deleted file mode 100644 (file)
index b1aa1e2..0000000
--- a/tp.h
+++ /dev/null
@@ -1,32 +0,0 @@
-#ifndef FIO_TP_H
-#define FIO_TP_H
-
-#include "flist.h"
-
-struct tp_work;
-typedef int (tp_work_fn)(struct tp_work *);
-
-struct tp_work {
-       struct flist_head list;
-       tp_work_fn *fn;
-       int wait;
-       pthread_cond_t cv;
-       pthread_mutex_t lock;
-       volatile int done;
-};
-
-struct tp_data {
-       pthread_t thread;
-       pthread_cond_t cv;
-       pthread_mutex_t lock;
-       struct flist_head work;
-       volatile int thread_exit;
-       pthread_cond_t sleep_cv;
-       volatile int sleeping;
-};
-
-extern void tp_init(struct tp_data **);
-extern void tp_exit(struct tp_data **);
-extern void tp_queue_work(struct tp_data *, struct tp_work *);
-
-#endif