RFC: add coroutines
@malureau
Submitted by Marc-André Lureau Link to original bug (#719362)
Description
Coroutines are used in various glib projects in C to simplify asynchronous and concurrent programming without requiring threads and avoiding synchronization issues.
This implementation is based on the gtk-vnc & qemu implementation written by Anthony Liguori anthony@codemonkey.ws and rewritten by Kevin Wolf kwolf@redhat.com to use setjmp()/longjmp() instead of the more expensive swapcontext(). I adopted coroutines in spice-gtk too. I made similar improvements independently there, so I think it's time that those 3 similar implementations become a single supported glib API that can be shared by those projects and others.
Furthermore, sharing an implementation could allow sharing future gdb debugging helpers, and tools. For example, some static analysis and CPS conversion tools are being worked on for qemu with interesting results (http://gabriel.kerneis.info/research/files/qemu-cpc.pdf)
The propsoed GLib implementation differs slightly from qemu. It aims to be safer (do not free the coroutine automatically on exit for example) and more generic (allows to send and return value between contexts). Contrary to qemu, there is no coroutine "recycle pool", since it can easily be implemented on top and is not considered useful enough in general.
TODO (before merge):
-
add coroutine locks support (from qemu) and/or spice-gtk condition
-
add thread and win fibers support
-
configure switch to choose implementation
-
propose other gobject/gio helpers from spice-gtk (later)