aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/osdep.c23
-rw-r--r--util/qemu-coroutine-io.c2
-rw-r--r--util/qemu-coroutine-lock.c26
-rw-r--r--util/qemu-coroutine-sleep.c2
-rw-r--r--util/qemu-coroutine.c10
5 files changed, 35 insertions, 28 deletions
diff --git a/util/osdep.c b/util/osdep.c
index ff004e8074..06fb1cfda6 100644
--- a/util/osdep.c
+++ b/util/osdep.c
@@ -83,14 +83,7 @@ static int qemu_dup_flags(int fd, int flags)
int serrno;
int dup_flags;
-#ifdef F_DUPFD_CLOEXEC
- ret = fcntl(fd, F_DUPFD_CLOEXEC, 0);
-#else
- ret = dup(fd);
- if (ret != -1) {
- qemu_set_cloexec(ret);
- }
-#endif
+ ret = qemu_dup(fd);
if (ret == -1) {
goto fail;
}
@@ -129,6 +122,20 @@ fail:
return -1;
}
+int qemu_dup(int fd)
+{
+ int ret;
+#ifdef F_DUPFD_CLOEXEC
+ ret = fcntl(fd, F_DUPFD_CLOEXEC, 0);
+#else
+ ret = dup(fd);
+ if (ret != -1) {
+ qemu_set_cloexec(ret);
+ }
+#endif
+ return ret;
+}
+
static int qemu_parse_fdset(const char *param)
{
return qemu_parse_fd(param);
diff --git a/util/qemu-coroutine-io.c b/util/qemu-coroutine-io.c
index 91b9357d4a..44a8969a69 100644
--- a/util/qemu-coroutine-io.c
+++ b/util/qemu-coroutine-io.c
@@ -75,7 +75,7 @@ static void fd_coroutine_enter(void *opaque)
{
FDYieldUntilData *data = opaque;
qemu_set_fd_handler(data->fd, NULL, NULL, NULL);
- qemu_coroutine_enter(data->co, NULL);
+ qemu_coroutine_enter(data->co);
}
void coroutine_fn yield_until_fd_readable(int fd)
diff --git a/util/qemu-coroutine-lock.c b/util/qemu-coroutine-lock.c
index da37ca7f95..22aa9abb30 100644
--- a/util/qemu-coroutine-lock.c
+++ b/util/qemu-coroutine-lock.c
@@ -31,13 +31,13 @@
void qemu_co_queue_init(CoQueue *queue)
{
- QTAILQ_INIT(&queue->entries);
+ QSIMPLEQ_INIT(&queue->entries);
}
void coroutine_fn qemu_co_queue_wait(CoQueue *queue)
{
Coroutine *self = qemu_coroutine_self();
- QTAILQ_INSERT_TAIL(&queue->entries, self, co_queue_next);
+ QSIMPLEQ_INSERT_TAIL(&queue->entries, self, co_queue_next);
qemu_coroutine_yield();
assert(qemu_in_coroutine());
}
@@ -55,9 +55,9 @@ void qemu_co_queue_run_restart(Coroutine *co)
Coroutine *next;
trace_qemu_co_queue_run_restart(co);
- while ((next = QTAILQ_FIRST(&co->co_queue_wakeup))) {
- QTAILQ_REMOVE(&co->co_queue_wakeup, next, co_queue_next);
- qemu_coroutine_enter(next, NULL);
+ while ((next = QSIMPLEQ_FIRST(&co->co_queue_wakeup))) {
+ QSIMPLEQ_REMOVE_HEAD(&co->co_queue_wakeup, co_queue_next);
+ qemu_coroutine_enter(next);
}
}
@@ -66,13 +66,13 @@ static bool qemu_co_queue_do_restart(CoQueue *queue, bool single)
Coroutine *self = qemu_coroutine_self();
Coroutine *next;
- if (QTAILQ_EMPTY(&queue->entries)) {
+ if (QSIMPLEQ_EMPTY(&queue->entries)) {
return false;
}
- while ((next = QTAILQ_FIRST(&queue->entries)) != NULL) {
- QTAILQ_REMOVE(&queue->entries, next, co_queue_next);
- QTAILQ_INSERT_TAIL(&self->co_queue_wakeup, next, co_queue_next);
+ while ((next = QSIMPLEQ_FIRST(&queue->entries)) != NULL) {
+ QSIMPLEQ_REMOVE_HEAD(&queue->entries, co_queue_next);
+ QSIMPLEQ_INSERT_TAIL(&self->co_queue_wakeup, next, co_queue_next);
trace_qemu_co_queue_next(next);
if (single) {
break;
@@ -97,19 +97,19 @@ bool qemu_co_enter_next(CoQueue *queue)
{
Coroutine *next;
- next = QTAILQ_FIRST(&queue->entries);
+ next = QSIMPLEQ_FIRST(&queue->entries);
if (!next) {
return false;
}
- QTAILQ_REMOVE(&queue->entries, next, co_queue_next);
- qemu_coroutine_enter(next, NULL);
+ QSIMPLEQ_REMOVE_HEAD(&queue->entries, co_queue_next);
+ qemu_coroutine_enter(next);
return true;
}
bool qemu_co_queue_empty(CoQueue *queue)
{
- return QTAILQ_FIRST(&queue->entries) == NULL;
+ return QSIMPLEQ_FIRST(&queue->entries) == NULL;
}
void qemu_co_mutex_init(CoMutex *mutex)
diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c
index 6966831d37..25de3ed3dd 100644
--- a/util/qemu-coroutine-sleep.c
+++ b/util/qemu-coroutine-sleep.c
@@ -25,7 +25,7 @@ static void co_sleep_cb(void *opaque)
{
CoSleepCB *sleep_cb = opaque;
- qemu_coroutine_enter(sleep_cb->co, NULL);
+ qemu_coroutine_enter(sleep_cb->co);
}
void coroutine_fn co_aio_sleep_ns(AioContext *ctx, QEMUClockType type,
diff --git a/util/qemu-coroutine.c b/util/qemu-coroutine.c
index 5816702cc5..89f21a9cec 100644
--- a/util/qemu-coroutine.c
+++ b/util/qemu-coroutine.c
@@ -42,7 +42,7 @@ static void coroutine_pool_cleanup(Notifier *n, void *value)
}
}
-Coroutine *qemu_coroutine_create(CoroutineEntry *entry)
+Coroutine *qemu_coroutine_create(CoroutineEntry *entry, void *opaque)
{
Coroutine *co = NULL;
@@ -76,7 +76,8 @@ Coroutine *qemu_coroutine_create(CoroutineEntry *entry)
}
co->entry = entry;
- QTAILQ_INIT(&co->co_queue_wakeup);
+ co->entry_arg = opaque;
+ QSIMPLEQ_INIT(&co->co_queue_wakeup);
return co;
}
@@ -100,12 +101,12 @@ static void coroutine_delete(Coroutine *co)
qemu_coroutine_delete(co);
}
-void qemu_coroutine_enter(Coroutine *co, void *opaque)
+void qemu_coroutine_enter(Coroutine *co)
{
Coroutine *self = qemu_coroutine_self();
CoroutineAction ret;
- trace_qemu_coroutine_enter(self, co, opaque);
+ trace_qemu_coroutine_enter(self, co, co->entry_arg);
if (co->caller) {
fprintf(stderr, "Co-routine re-entered recursively\n");
@@ -113,7 +114,6 @@ void qemu_coroutine_enter(Coroutine *co, void *opaque)
}
co->caller = self;
- co->entry_arg = opaque;
ret = qemu_coroutine_switch(self, co, COROUTINE_ENTER);
qemu_co_queue_run_restart(co);