diff --git a/CMakeLists.txt b/CMakeLists.txt index 713c1f3..e9a62e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,10 +13,13 @@ target_compile_options(${PROJECT_NAME} PRIVATE -W -Wall -Wextra -Werror) find_package(PkgConfig REQUIRED) pkg_check_modules(GLIB2 REQUIRED glib-2.0) +pkg_check_modules(GIO2 REQUIRED gio-2.0) target_include_directories(${PROJECT_NAME} PUBLIC ${GLIB2_INCLUDE_DIRS}) target_link_libraries(${PROJECT_NAME} ${GLIB2_LIBRARIES}) +target_include_directories(${PROJECT_NAME} PRIVATE ${GIO2_INCLUDE_DIRS}) +target_link_libraries(${PROJECT_NAME} ${GIO2_LIBRARIES}) target_link_libraries(${PROJECT_NAME} m) diff --git a/coio.c b/coio.c index fe7a3d3..b97ea50 100644 --- a/coio.c +++ b/coio.c @@ -32,7 +32,7 @@ CoioTaskList coio_ready_list = {0, 0}; CoioTaskList coio_sleeping = {0, 0}; coro_context coio_sched_ctx; -CoioTask* coio_current; +CoioTask* coio_current = NULL; unsigned long coio_taskcount = 0; static int msleep(uvlong ms) diff --git a/coio_glib.c b/coio_glib.c index 360b3b8..7a0d2ec 100644 --- a/coio_glib.c +++ b/coio_glib.c @@ -19,6 +19,7 @@ #include "coioimpl.h" #include +#include struct coio_source { GSource base; @@ -68,7 +69,10 @@ static gboolean coio_source_check(GSource* source) } } - return TRUE; + if (coio_ready_list.head) + return TRUE; + + return FALSE; } static gboolean coio_source_dispatch(GSource* source, GSourceFunc callback, gpointer user_data) @@ -77,10 +81,6 @@ static gboolean coio_source_dispatch(GSource* source, GSourceFunc callback, gpoi CoioTask* last; gboolean result = G_SOURCE_CONTINUE; - /* error condition */ - if (!coio_ready_list.head && !coio_sleeping.head) - return G_SOURCE_REMOVE; - if (!coio_ready_list.head) return G_SOURCE_CONTINUE; @@ -99,6 +99,8 @@ static gboolean coio_source_dispatch(GSource* source, GSourceFunc callback, gpoi } } while (coio_current != last); + coio_current = NULL; + if (callback) { result = callback(user_data); } @@ -132,3 +134,11 @@ gboolean coio_task_wakeup_helper(gpointer task) coio_ready((CoioTask*)task); return G_SOURCE_REMOVE; } + +void coio_gasyncresult_wakeup_helper(GObject *source_object, GAsyncResult *res, gpointer user_data) +{ + (void)source_object; + CoioGAsyncResultHelper* helper = (CoioGAsyncResultHelper*)user_data; + helper->res = g_object_ref(res); + coio_ready(helper->task); +} diff --git a/coio_glib.h b/coio_glib.h index 7844470..8cc7f3e 100644 --- a/coio_glib.h +++ b/coio_glib.h @@ -18,8 +18,16 @@ #define COIO_GLIB_H #include +#include +#include "coio.h" + +typedef struct async_helper { + CoioTask* task; + GAsyncResult* res; +} CoioGAsyncResultHelper; GSource* coio_gsource_create(); gboolean coio_task_wakeup_helper(gpointer task); +void coio_gasyncresult_wakeup_helper(GObject *source_object, GAsyncResult *res, gpointer user_data); #endif