+/*
+ * Basic workqueue like code, that sets up a thread and allows async
+ * processing of some sort. Could be extended to allow for multiple
+ * worker threads. But right now fio associates one of this per IO
+ * thread, so should be enough to have just a single thread doing the
+ * work.
+ */
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
#include <errno.h>
#include <pthread.h>
+#include <string.h>
#include "../smalloc.h"
#include "../log.h"
struct tp_work *work;
while (!flist_empty(list)) {
+ int prio;
+
work = flist_entry(list->next, struct tp_work, list);
flist_del(&work->list);
+
+ prio = work->prio;
+ if (nice(prio) < 0)
+ log_err("fio: nice %s\n", strerror(errno));
+
work->fn(work);
+
+ if (nice(prio) < 0)
+ log_err("fio: nice %s\n", strerror(errno));
}
}
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);
- }
+ if (!flist_empty(&tdat->work))
+ flist_splice_tail_init(&tdat->work, &work_list);
pthread_mutex_unlock(&tdat->lock);
pthread_mutex_lock(&tdat->lock);
flist_add_tail(&work->list, &tdat->work);
- pthread_cond_signal(&tdat->cv);
pthread_mutex_unlock(&tdat->lock);
+
+ pthread_cond_signal(&tdat->cv);
}
void tp_init(struct tp_data **tdatp)
if (!tdat)
return;
- tdat->thread_exit = 1;
pthread_mutex_lock(&tdat->lock);
- pthread_cond_signal(&tdat->cv);
+ tdat->thread_exit = 1;
pthread_mutex_unlock(&tdat->lock);
+ pthread_cond_signal(&tdat->cv);
+
pthread_join(tdat->thread, &ret);
sfree(tdat);