[Spice-devel] [PATCH] gtask-helper: include functions to check coroutine context
Victor Toso
victortoso at redhat.com
Sat May 14 15:03:37 UTC 2016
If we are in coroutine context, fallback to return in idle; Otherwise,
let GTask decide if callback should be called or not.
---
src/gtask-helper.h | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/src/gtask-helper.h b/src/gtask-helper.h
index 81c041f..8771021 100644
--- a/src/gtask-helper.h
+++ b/src/gtask-helper.h
@@ -29,6 +29,51 @@ void g_task_helper_return_error_in_idle(GTask *task, GError *error);
void g_task_helper_return_new_error_in_idle(GTask *task, GQuark domain, gint code, const char *format, ...);
void g_task_helper_return_pointer_in_idle(GTask *task, gpointer result, GDestroyNotify result_destroy);
+#define g_task_helper_return_boolean(...) \
+ do { \
+ if (coroutine_self_is_main()) { \
+ g_task_return_boolean(__VA_ARGS__); \
+ } else { \
+ g_task_helper_return_boolean_in_idle(__VA_ARGS__); \
+ } \
+ } while (0)
+
+#define g_task_helper_return_int(...) \
+ do { \
+ if (coroutine_self_is_main()) { \
+ g_task_return_int(__VA_ARGS__); \
+ } else { \
+ g_task_helper_return_int_in_idle(__VA_ARGS__); \
+ } \
+ } while (0)
+
+#define g_task_helper_return_error(...) \
+ do { \
+ if (coroutine_self_is_main()) { \
+ g_task_return_error(__VA_ARGS__); \
+ } else { \
+ g_task_helper_return_error_in_idle(__VA_ARGS__); \
+ } \
+ } while (0)
+
+#define g_task_helper_return_new_error(...) \
+ do { \
+ if (coroutine_self_is_main()) { \
+ g_task_return_new_error(__VA_ARGS__); \
+ } else { \
+ g_task_helper_return_new_error_in_idle(__VA_ARGS__); \
+ } \
+ } while (0)
+
+#define g_task_helper_return_pointer(...) \
+ do { \
+ if (coroutine_self_is_main()) { \
+ g_task_return_pointer(__VA_ARGS__); \
+ } else { \
+ g_task_helper_return_pointer_in_idle(__VA_ARGS__); \
+ } \
+ } while (0)
+
G_END_DECLS
#endif /* __G_TASK_HELPER_H__ */
--
2.5.5
More information about the Spice-devel
mailing list