Add gio helper and clean up glib related code

This commit is contained in:
Moritz Bitsch 2018-07-30 11:58:55 +02:00
parent 1cae7a8b27
commit 3af6983505
4 changed files with 27 additions and 6 deletions

View file

@ -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)

2
coio.c
View file

@ -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)

View file

@ -19,6 +19,7 @@
#include "coioimpl.h"
#include <glib.h>
#include <gio/gio.h>
struct coio_source {
GSource base;
@ -68,7 +69,10 @@ static gboolean coio_source_check(GSource* source)
}
}
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);
}

View file

@ -18,8 +18,16 @@
#define COIO_GLIB_H
#include <glib.h>
#include <gio/gio.h>
#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