This patch adds submit work threadlet API and shows how
the qemu_paio_submit changes to submit_work.

Signed-off-by: Arun R Bharadwaj <a...@linux.vnet.ibm.com>
---
 posix-aio-compat.c |   33 ++++++++++++++++++++++-----------
 1 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/posix-aio-compat.c b/posix-aio-compat.c
index 7b41235..ff6e08b 100644
--- a/posix-aio-compat.c
+++ b/posix-aio-compat.c
@@ -393,13 +393,13 @@ static void spawn_threadlet(ThreadletQueue *queue)
 }
 
 
-static void qemu_paio_submit(struct qemu_paiocb *aiocb)
+/**
+ * submit_work: Submit to the global queue a new task to be executed
+ *                   asynchronously.
+ * @work: Contains information about the task that needs to be submitted.
+ */
+static void submit_work(ThreadletWork *work)
 {
-    qemu_mutex_lock(&aiocb_mutex);
-    aiocb->ret = -EINPROGRESS;
-    aiocb->active = 0;
-    qemu_mutex_unlock(&aiocb_mutex);
-
     qemu_mutex_lock(&globalqueue.lock);
 
     if (!globalqueue_init) {
@@ -415,13 +415,13 @@ static void qemu_paio_submit(struct qemu_paiocb *aiocb)
     }
 
     if (globalqueue.idle_threads == 0 &&
-        globalqueue.cur_threads < globalqueue.max_threads)
+        globalqueue.cur_threads < globalqueue.max_threads) {
         spawn_threadlet(&globalqueue);
 
-    aiocb->work.func = aio_thread;
-
-    QTAILQ_INSERT_TAIL(&globalqueue.request_list, &aiocb->work, node);
-    qemu_cond_signal(&globalqueue.cond);
+    } else {
+        qemu_cond_signal(&globalqueue.cond);
+    }
+    QTAILQ_INSERT_TAIL(&globalqueue.request_list, work, node);
     qemu_mutex_unlock(&globalqueue.lock);
 }
 
@@ -448,6 +448,17 @@ static int qemu_paio_error(struct qemu_paiocb *aiocb)
     return ret;
 }
 
+static void qemu_paio_submit(struct qemu_paiocb *aiocb)
+{
+    qemu_mutex_lock(&aiocb_mutex);
+    aiocb->ret = -EINPROGRESS;
+    aiocb->active = 0;
+    qemu_mutex_unlock(&aiocb_mutex);
+
+    aiocb->work.func = aio_thread;
+    submit_work(&aiocb->work);
+}
+
 static int posix_aio_process_queue(void *opaque)
 {
     PosixAioState *s = opaque;


Reply via email to