summary refs log tree commit diff stats
path: root/include/qemu/coroutine.h
diff options
context:
space:
mode:
authorVladimir Sementsov-Ogievskiy <vsementsov@openvz.org>2022-04-07 16:27:23 +0300
committerVladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>2022-06-29 10:56:12 +0300
commite1878eb5f0d93a67deb46aaeea898cf4824a759a (patch)
tree6601b84c8a70c4cad699e0d65f9c4f318a5021c8 /include/qemu/coroutine.h
parentdd3e97dfbe199fa277869d127884071100a426e5 (diff)
downloadfocaccia-qemu-e1878eb5f0d93a67deb46aaeea898cf4824a759a.tar.gz
focaccia-qemu-e1878eb5f0d93a67deb46aaeea898cf4824a759a.zip
util: add qemu-co-timeout
Add new API, to make a time limited call of the coroutine.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@openvz.org>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Diffstat (limited to 'include/qemu/coroutine.h')
-rw-r--r--include/qemu/coroutine.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h
index d1548d5b11..08c5bb3c76 100644
--- a/include/qemu/coroutine.h
+++ b/include/qemu/coroutine.h
@@ -331,6 +331,19 @@ static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64_t ns)
     qemu_co_sleep_ns_wakeable(&w, type, ns);
 }
 
+typedef void CleanupFunc(void *opaque);
+/**
+ * Run entry in a coroutine and start timer. Wait for entry to finish or for
+ * timer to elapse, what happen first. If entry finished, return 0, if timer
+ * elapsed earlier, return -ETIMEDOUT.
+ *
+ * Be careful, entry execution is not canceled, user should handle it somehow.
+ * If @clean is provided, it's called after coroutine finish if timeout
+ * happened.
+ */
+int coroutine_fn qemu_co_timeout(CoroutineEntry *entry, void *opaque,
+                                 uint64_t timeout_ns, CleanupFunc clean);
+
 /**
  * Wake a coroutine if it is sleeping in qemu_co_sleep_ns. The timer will be
  * deleted. @sleep_state must be the variable whose address was given to