diff options
author | osy <osy@turing.llc> | 2022-03-04 15:52:48 -0800 |
---|---|---|
committer | osy <osy@turing.llc> | 2022-03-04 21:56:12 -0800 |
commit | fa812c88492641005a768c72502a8953bd1223b2 (patch) | |
tree | 0486e262a45340eaac567b9abf6e27f51ecda073 | |
parent | 9f3b720e2f7fa793b263f12bb50f19f60b863760 (diff) |
coroutine: add support for libucontext
libucontext is a lightweight implementation of ucontext for platforms
that do not have a built-in implementation. This allows us to use the
same code to support libucontext as ucontext.
-rw-r--r-- | meson.build | 7 | ||||
-rw-r--r-- | meson_options.txt | 2 | ||||
-rw-r--r-- | src/continuation.c | 12 | ||||
-rw-r--r-- | src/meson.build | 2 |
4 files changed, 20 insertions, 3 deletions
diff --git a/meson.build b/meson.build index 11173fd..ec13ac3 100644 --- a/meson.build +++ b/meson.build @@ -317,6 +317,13 @@ if spice_gtk_coroutine == 'ucontext' endif endif +if spice_gtk_coroutine == 'libucontext' + d = dependency('libucontext') + spice_glib_deps += d + spice_gtk_config_data.set('WITH_UCONTEXT', '1') + spice_gtk_config_data.set('HAVE_LIBUCONTEXT', '1') +endif + if spice_gtk_coroutine == 'gthread' spice_gtk_config_data.set('WITH_GTHREAD', '1') endif diff --git a/meson_options.txt b/meson_options.txt index 3cbc7c6..5acfc9a 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -45,7 +45,7 @@ option('usb-ids-path', option('coroutine', type : 'combo', value : 'auto', - choices : ['auto', 'ucontext', 'gthread', 'winfiber'], + choices : ['auto', 'ucontext', 'libucontext', 'gthread', 'winfiber'], description : 'Use ucontext or GThread for coroutines') option('introspection', diff --git a/src/continuation.c b/src/continuation.c index 65527ac..400169a 100644 --- a/src/continuation.c +++ b/src/continuation.c @@ -25,11 +25,21 @@ #endif #include <errno.h> -#include <ucontext.h> #include <glib.h> #include "continuation.h" +#ifdef HAVE_LIBUCONTEXT +#include <libucontext/libucontext.h> +#define ucontext_t libucontext_ucontext_t +#define getcontext libucontext_getcontext +#define setcontext libucontext_setcontext +#define swapcontext libucontext_swapcontext +#define makecontext libucontext_makecontext +#else +#include <ucontext.h> +#endif + /* * va_args to makecontext() must be type 'int', so passing * the pointer we need may require several int args. This diff --git a/src/meson.build b/src/meson.build index a9dfc57..961779f 100644 --- a/src/meson.build +++ b/src/meson.build @@ -146,7 +146,7 @@ endif if spice_gtk_coroutine == 'gthread' spice_client_glib_sources += 'coroutine_gthread.c' -elif spice_gtk_coroutine == 'ucontext' +elif spice_gtk_coroutine in ['ucontext', 'libucontext'] spice_client_glib_sources += ['continuation.c', 'continuation.h', 'coroutine_ucontext.c'] |