From 0f162e365c8dffb552b4044700221e05537e3416 Mon Sep 17 00:00:00 2001 From: Moritz Bitsch Date: Fri, 27 Jul 2018 08:49:34 +0200 Subject: [PATCH 1/4] Add glib integration this allows us to use all glib features together with coroutines in the same thread --- Makefile | 5 +- coio.c | 43 ++++++++++++------ coio_glib.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++ coio_glib.h | 24 ++++++++++ coioimpl.h | 2 + 5 files changed, 188 insertions(+), 15 deletions(-) create mode 100644 coio_glib.c create mode 100644 coio_glib.h diff --git a/Makefile b/Makefile index 0e957d5..7322466 100644 --- a/Makefile +++ b/Makefile @@ -2,14 +2,15 @@ LIB = libcoio.a OBJS = \ coro.o \ - coio.o + coio.o \ + coio_glib.o all: $(LIB) $(OBJS): coio.h coro.h .c.o: - $(CC) $(CFLAGS) -W -Wall -Wextra -Werror -c $*.c + $(CC) $(shell pkg-config --cflags glib-2.0) $(CFLAGS) -W -Wall -Wextra -Werror -c $*.c $(LIB): $(OBJS) $(AR) rvc $(LIB) $? diff --git a/coio.c b/coio.c index d936e0c..b5db6f2 100644 --- a/coio.c +++ b/coio.c @@ -13,8 +13,11 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#define _POSIX_C_SOURCE 200809L + #include #include +#include #include "coioimpl.h" #include "coro.h" @@ -24,12 +27,26 @@ #include #endif -static coro_context _sched_ctx; -static unsigned long _taskcount = 0; - CoioTaskList coio_ready = {0, 0}; CoioTaskList coio_sleeping = {0, 0}; +coro_context coio_sched_ctx; CoioTask *coio_current; +unsigned long coio_taskcount = 0; + +static int msleep(uvlong ms) +{ + struct timespec req, rem; + + if(ms > 999) { + req.tv_sec = (int)(ms / 1000); + req.tv_nsec = (ms - ((long)req.tv_sec * 1000)) * 1000000; + } else { + req.tv_sec = 0; + req.tv_nsec = ms * 1000000; + } + + return nanosleep(&req , &rem); +} static void _process_events() @@ -47,7 +64,7 @@ _process_events() } } /* TODO:do I/O polling instead of usleep */ - usleep(ms * 1000); + msleep(ms); /* handle CLOCK_MONOTONIC bugs (VirtualBox anyone?) */ while (!coio_ready.head) { @@ -63,7 +80,7 @@ int coio_main() { /* initialize empty ctx for scheduler */ - coro_create(&_sched_ctx, NULL, NULL, NULL, 0); + coro_create(&coio_sched_ctx, NULL, NULL, NULL, 0); /* scheduler mainloop */ for (;;) { @@ -75,17 +92,17 @@ coio_main() coio_current = coio_ready.head; coio_del(&coio_ready, coio_current); - coro_transfer(&_sched_ctx, &coio_current->ctx); + coro_transfer(&coio_sched_ctx, &coio_current->ctx); if (coio_current->done) { - _taskcount--; + coio_taskcount--; coro_stack_free(&coio_current->stk); free(coio_current); } coio_current = NULL; } - if (_taskcount) { + if (coio_taskcount) { return -1; } return 0; @@ -99,7 +116,7 @@ _coio_entry(void *arg) task->func(task->arg); task->done = 1; - coro_transfer(&coio_current->ctx, &_sched_ctx); + coro_transfer(&coio_current->ctx, &coio_sched_ctx); } int @@ -121,7 +138,7 @@ coio_create(coio_func f, void *arg, unsigned int stacksize) coro_create(&task->ctx, _coio_entry, task, task->stk.sptr, task->stk.ssze); coio_add(&coio_ready, task); - _taskcount++; + coio_taskcount++; return 0; } @@ -196,13 +213,13 @@ coio_del(CoioTaskList * lst, CoioTask * task) { if (task->prev) { task->prev->next = task->next; - } else { + } else if (lst->head == task) { lst->head = task->next; } if (task->next) { task->next->prev = task->prev; - } else { + } else if (lst->tail == task) { lst->tail = task->prev; } } @@ -218,7 +235,7 @@ coio_rdy(CoioTask * task) void coio_transfer() { - coro_transfer(&coio_current->ctx, &_sched_ctx); + coro_transfer(&coio_current->ctx, &coio_sched_ctx); } uvlong diff --git a/coio_glib.c b/coio_glib.c new file mode 100644 index 0000000..0c7626c --- /dev/null +++ b/coio_glib.c @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2018 Moritz Bitsch + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "coio_glib.h" +#include "coio.h" +#include "coioimpl.h" + +#include + +struct coio_source +{ + GSource base; +}; + +static gboolean coio_source_prepare(GSource* source, gint* timeout_) +{ + (void)source; + uvlong now; + int ms = 5; + CoioTask* t; + + if (coio_ready.head) { + *timeout_ = 0; + + /* if we return true here our check functions do not get called */ + if (coio_sleeping.head) { + return FALSE; + } + + return TRUE; + } + + if ((t = coio_sleeping.head) != NULL && t->timeout != 0) { + now = coio_now(); + if (now >= t->timeout) { + ms = 0; + } else { + ms = (t->timeout - now) / 1000000; + } + } + + *timeout_ = ms; + return FALSE; +} + +static gboolean coio_source_check(GSource* source) +{ + (void)source; + CoioTask* t; + + if (coio_sleeping.head) { + /* wake up timed out tasks */ + uvlong now = coio_now(); + while ((t = coio_sleeping.head) && now >= t->timeout) { + coio_rdy(t); + } + } + + return TRUE; +} + +static gboolean coio_source_dispatch(GSource* source, GSourceFunc callback, gpointer user_data) +{ + (void)source; + CoioTask* last; + gboolean result = G_SOURCE_CONTINUE; + + /* error condition */ + if (!coio_ready.head && !coio_sleeping.head) + return G_SOURCE_REMOVE; + + if (!coio_ready.head) + return G_SOURCE_CONTINUE; + + last = coio_ready.tail; + + do { + coio_current = coio_ready.head; + coio_del(&coio_ready, coio_current); + coro_transfer(&coio_sched_ctx, &coio_current->ctx); + + if (coio_current->done) { + coio_taskcount--; + coro_stack_free(&coio_current->stk); + free(coio_current); + } + } while (coio_current != last); + + if (callback) { + result = callback(user_data); + } + + return result; +} + +static void coio_source_finalize(GSource* source) +{ + (void)source; +} + +GSource* coio_gsource_create() +{ + coro_create(&coio_sched_ctx, NULL, NULL, NULL, 0); + + static GSourceFuncs funcs = + { + coio_source_prepare, + coio_source_check, + coio_source_dispatch, + coio_source_finalize, + NULL, + NULL + }; + + return g_source_new(&funcs, sizeof(struct coio_source)); +} diff --git a/coio_glib.h b/coio_glib.h new file mode 100644 index 0000000..758ec47 --- /dev/null +++ b/coio_glib.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2018 Moritz Bitsch + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef COIO_GLIB_H +#define COIO_GLIB_H + +#include + +GSource* coio_gsource_create(); + +#endif diff --git a/coioimpl.h b/coioimpl.h index 0acd967..ec03442 100644 --- a/coioimpl.h +++ b/coioimpl.h @@ -44,6 +44,8 @@ struct CoioTaskList { extern CoioTaskList coio_ready; extern CoioTaskList coio_sleeping; extern CoioTask *coio_current; +extern coro_context coio_sched_ctx; +extern unsigned long coio_taskcount; void coio_add (CoioTaskList * lst, CoioTask * task); void coio_del (CoioTaskList * lst, CoioTask * task); From 675bccefd6a01212de80e97a2d7192847ca06a1f Mon Sep 17 00:00:00 2001 From: Moritz Bitsch Date: Fri, 27 Jul 2018 10:39:43 +0200 Subject: [PATCH 2/4] Add infinite delay and external wakeup support this is useful if you want to wait for a glib signal/callback --- coio.c | 64 +++++++++++++++++++++++++++++++++++++++-------------- coio.h | 5 ++++- coio_glib.c | 23 ++++++++++++------- coio_glib.h | 1 + coioimpl.h | 7 +++--- 5 files changed, 71 insertions(+), 29 deletions(-) diff --git a/coio.c b/coio.c index b5db6f2..ade89f1 100644 --- a/coio.c +++ b/coio.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "coioimpl.h" #include "coro.h" @@ -27,7 +28,7 @@ #include #endif -CoioTaskList coio_ready = {0, 0}; +CoioTaskList coio_ready_list = {0, 0}; CoioTaskList coio_sleeping = {0, 0}; coro_context coio_sched_ctx; CoioTask *coio_current; @@ -67,11 +68,11 @@ _process_events() msleep(ms); /* handle CLOCK_MONOTONIC bugs (VirtualBox anyone?) */ - while (!coio_ready.head) { + while (!coio_ready_list.head) { /* wake up timed out tasks */ now = coio_now(); - while ((t = coio_sleeping.head) && now >= t->timeout) { - coio_rdy(t); + while ((t = coio_sleeping.head) && t->timeout && now >= t->timeout) { + coio_ready(t); } } } @@ -84,14 +85,15 @@ coio_main() /* scheduler mainloop */ for (;;) { - if (!coio_ready.head && coio_sleeping.head) + if (!coio_ready_list.head && coio_sleeping.head) _process_events(); - if (!coio_ready.head) + if (!coio_ready_list.head) break; - coio_current = coio_ready.head; - coio_del(&coio_ready, coio_current); + coio_current = coio_ready_list.head; + coio_current->ready = 0; + coio_del(&coio_ready_list, coio_current); coro_transfer(&coio_sched_ctx, &coio_current->ctx); if (coio_current->done) { @@ -120,7 +122,7 @@ _coio_entry(void *arg) } int -coio_create(coio_func f, void *arg, unsigned int stacksize) +coio_create(const char* name, coio_func f, void *arg, unsigned int stacksize) { CoioTask *task; @@ -132,12 +134,13 @@ coio_create(coio_func f, void *arg, unsigned int stacksize) free(task); return -1; } + task->name = name; task->func = f; task->arg = arg; coro_create(&task->ctx, _coio_entry, task, task->stk.sptr, task->stk.ssze); - coio_add(&coio_ready, task); + coio_add(&coio_ready_list, task); coio_taskcount++; return 0; @@ -148,10 +151,13 @@ coio_timeout(CoioTask * task, int ms) { CoioTask *t; - if (ms > 0) + if (ms >= 0) { task->timeout = coio_now() + (ms * 1000000); - - for (t = coio_sleeping.head; t != NULL && t->timeout && t->timeout < task->timeout; t = t->next); + for (t = coio_sleeping.head; t != NULL && t->timeout && t->timeout < task->timeout; t = t->next); + } else { + task->timeout = 0; + t = NULL; + } if (t) { task->prev = t->prev; @@ -190,7 +196,7 @@ coio_delay(int ms) void coio_yield() { - coio_rdy(coio_current); + coio_ready(coio_current); coio_transfer(); } @@ -225,11 +231,14 @@ coio_del(CoioTaskList * lst, CoioTask * task) } void -coio_rdy(CoioTask * task) +coio_ready(CoioTask * task) { task->timeout = 0; - coio_del(&coio_sleeping, task); - coio_add(&coio_ready, task); + if (!task->ready) { + task->ready = 1; + coio_del(&coio_sleeping, task); + coio_add(&coio_ready_list, task); + } } void @@ -259,3 +268,24 @@ coio_now() return (uvlong) ts.tv_sec * 1000 * 1000 * 1000 + ts.tv_nsec; #endif } + +void +coio_debug() +{ + CoioTask *t; + + fprintf(stderr, ">>>\nCurrent tasks: %s\n", coio_current->name); + + fprintf(stderr, "Sleeping tasks: "); + for (t = coio_sleeping.head; t != NULL; t = t->next) + { + fprintf(stderr, "%s ", t->name); + } + + fprintf(stderr, "\nReady tasks: "); + for (t = coio_ready_list.head; t != NULL; t = t->next) + { + fprintf(stderr, "%s ", t->name); + } + fprintf(stderr, "\n"); +} diff --git a/coio.h b/coio.h index 20a7e6c..1b7aaf9 100644 --- a/coio.h +++ b/coio.h @@ -24,11 +24,14 @@ extern "C" { typedef void (*coio_func) (void *arg); typedef unsigned long long uvlong; + extern CoioTask *coio_current; + int coio_main (); - int coio_create(coio_func f, void *arg, unsigned int stacksize); + int coio_create(const char* name, coio_func f, void *arg, unsigned int stacksize); void coio_yield(); uvlong coio_now(); int coio_delay(int ms); + void coio_ready(CoioTask * task); #ifdef __cplusplus } diff --git a/coio_glib.c b/coio_glib.c index 0c7626c..6e90256 100644 --- a/coio_glib.c +++ b/coio_glib.c @@ -32,7 +32,7 @@ static gboolean coio_source_prepare(GSource* source, gint* timeout_) int ms = 5; CoioTask* t; - if (coio_ready.head) { + if (coio_ready_list.head) { *timeout_ = 0; /* if we return true here our check functions do not get called */ @@ -64,8 +64,8 @@ static gboolean coio_source_check(GSource* source) if (coio_sleeping.head) { /* wake up timed out tasks */ uvlong now = coio_now(); - while ((t = coio_sleeping.head) && now >= t->timeout) { - coio_rdy(t); + while ((t = coio_sleeping.head) && t->timeout && now >= t->timeout) { + coio_ready(t); } } @@ -79,17 +79,18 @@ static gboolean coio_source_dispatch(GSource* source, GSourceFunc callback, gpoi gboolean result = G_SOURCE_CONTINUE; /* error condition */ - if (!coio_ready.head && !coio_sleeping.head) + if (!coio_ready_list.head && !coio_sleeping.head) return G_SOURCE_REMOVE; - if (!coio_ready.head) + if (!coio_ready_list.head) return G_SOURCE_CONTINUE; - last = coio_ready.tail; + last = coio_ready_list.tail; do { - coio_current = coio_ready.head; - coio_del(&coio_ready, coio_current); + coio_current = coio_ready_list.head; + coio_current->ready = 0; + coio_del(&coio_ready_list, coio_current); coro_transfer(&coio_sched_ctx, &coio_current->ctx); if (coio_current->done) { @@ -127,3 +128,9 @@ GSource* coio_gsource_create() return g_source_new(&funcs, sizeof(struct coio_source)); } + +gboolean coio_task_wakeup_helper(gpointer task) +{ + coio_ready((CoioTask*)task); + return G_SOURCE_REMOVE; +} diff --git a/coio_glib.h b/coio_glib.h index 758ec47..7844470 100644 --- a/coio_glib.h +++ b/coio_glib.h @@ -20,5 +20,6 @@ #include GSource* coio_gsource_create(); +gboolean coio_task_wakeup_helper(gpointer task); #endif diff --git a/coioimpl.h b/coioimpl.h index ec03442..1039702 100644 --- a/coioimpl.h +++ b/coioimpl.h @@ -25,10 +25,12 @@ struct CoioTask { coro_context ctx; struct coro_stack stk; + const char *name; coio_func func; void *arg; uvlong timeout; + int ready; int done; /* linked list support */ @@ -41,15 +43,14 @@ struct CoioTaskList { CoioTask *tail; }; -extern CoioTaskList coio_ready; +extern CoioTaskList coio_ready_list; extern CoioTaskList coio_sleeping; -extern CoioTask *coio_current; extern coro_context coio_sched_ctx; extern unsigned long coio_taskcount; void coio_add (CoioTaskList * lst, CoioTask * task); void coio_del (CoioTaskList * lst, CoioTask * task); -void coio_rdy (CoioTask * task); void coio_transfer(); +void coio_debug(); #endif From c41a8ca6b406a057d7374d381be4f041d6acb1a5 Mon Sep 17 00:00:00 2001 From: Moritz Bitsch Date: Fri, 27 Jul 2018 10:41:06 +0200 Subject: [PATCH 3/4] Add CMakeLists.txt * support building with cmake --- CMakeLists.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e87f17c --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 3.7) +project(coio) + +add_library(${PROJECT_NAME} + coro.c + coio.c + coio_glib.c) + +add_custom_target(${PROJECT_NAME}_files SOURCES coioimpl.h) + +set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 99) +target_compile_options(${PROJECT_NAME} PRIVATE -W -Wall -Wextra -Werror) + +find_package(PkgConfig REQUIRED) +pkg_check_modules(GLIB2 REQUIRED glib-2.0) + +target_include_directories(${PROJECT_NAME} PUBLIC ${GLIB2_INCLUDE_DIRS}) +target_link_libraries(${PROJECT_NAME} ${GLIB2_LIBRARIES}) + +target_include_directories(${PROJECT_NAME} PUBLIC .) From c801b183dc8e5da885a3e1df92fd42e036b56a87 Mon Sep 17 00:00:00 2001 From: Moritz Bitsch Date: Fri, 27 Jul 2018 10:45:00 +0200 Subject: [PATCH 4/4] Reformat code run astyle --style=linux on source files --- coio.c | 36 +++++++++++++++++------------------- coio.h | 20 ++++++++++---------- coio_glib.c | 6 ++---- coioimpl.h | 16 ++++++++-------- testdelay.c | 4 ++-- testyield.c | 6 +++--- 6 files changed, 42 insertions(+), 46 deletions(-) diff --git a/coio.c b/coio.c index ade89f1..a33bb33 100644 --- a/coio.c +++ b/coio.c @@ -31,14 +31,14 @@ CoioTaskList coio_ready_list = {0, 0}; CoioTaskList coio_sleeping = {0, 0}; coro_context coio_sched_ctx; -CoioTask *coio_current; +CoioTask* coio_current; unsigned long coio_taskcount = 0; static int msleep(uvlong ms) { struct timespec req, rem; - if(ms > 999) { + if (ms > 999) { req.tv_sec = (int)(ms / 1000); req.tv_nsec = (ms - ((long)req.tv_sec * 1000)) * 1000000; } else { @@ -46,7 +46,7 @@ static int msleep(uvlong ms) req.tv_nsec = ms * 1000000; } - return nanosleep(&req , &rem); + return nanosleep(&req, &rem); } static void @@ -54,7 +54,7 @@ _process_events() { uvlong now; int ms = 5; - CoioTask *t; + CoioTask* t; if ((t = coio_sleeping.head) != NULL && t->timeout != 0) { now = coio_now(); @@ -111,9 +111,9 @@ coio_main() } static void -_coio_entry(void *arg) +_coio_entry(void* arg) { - CoioTask *task = (CoioTask *) arg; + CoioTask* task = (CoioTask*) arg; task->func(task->arg); @@ -122,15 +122,15 @@ _coio_entry(void *arg) } int -coio_create(const char* name, coio_func f, void *arg, unsigned int stacksize) +coio_create(const char* name, coio_func f, void* arg, unsigned int stacksize) { - CoioTask *task; + CoioTask* task; task = calloc(1, sizeof(*task)); if (!task) return -1; - if (!coro_stack_alloc(&task->stk, stacksize / sizeof(void *))) { + if (!coro_stack_alloc(&task->stk, stacksize / sizeof(void*))) { free(task); return -1; } @@ -147,9 +147,9 @@ coio_create(const char* name, coio_func f, void *arg, unsigned int stacksize) } uvlong -coio_timeout(CoioTask * task, int ms) +coio_timeout(CoioTask* task, int ms) { - CoioTask *t; + CoioTask* t; if (ms >= 0) { task->timeout = coio_now() + (ms * 1000000); @@ -201,7 +201,7 @@ coio_yield() } void -coio_add(CoioTaskList * lst, CoioTask * task) +coio_add(CoioTaskList* lst, CoioTask* task) { if (lst->tail) { lst->tail->next = task; @@ -215,7 +215,7 @@ coio_add(CoioTaskList * lst, CoioTask * task) } void -coio_del(CoioTaskList * lst, CoioTask * task) +coio_del(CoioTaskList* lst, CoioTask* task) { if (task->prev) { task->prev->next = task->next; @@ -231,7 +231,7 @@ coio_del(CoioTaskList * lst, CoioTask * task) } void -coio_ready(CoioTask * task) +coio_ready(CoioTask* task) { task->timeout = 0; if (!task->ready) { @@ -272,19 +272,17 @@ coio_now() void coio_debug() { - CoioTask *t; + CoioTask* t; fprintf(stderr, ">>>\nCurrent tasks: %s\n", coio_current->name); fprintf(stderr, "Sleeping tasks: "); - for (t = coio_sleeping.head; t != NULL; t = t->next) - { + for (t = coio_sleeping.head; t != NULL; t = t->next) { fprintf(stderr, "%s ", t->name); } fprintf(stderr, "\nReady tasks: "); - for (t = coio_ready_list.head; t != NULL; t = t->next) - { + for (t = coio_ready_list.head; t != NULL; t = t->next) { fprintf(stderr, "%s ", t->name); } fprintf(stderr, "\n"); diff --git a/coio.h b/coio.h index 1b7aaf9..de236b9 100644 --- a/coio.h +++ b/coio.h @@ -20,18 +20,18 @@ extern "C" { #endif - typedef struct CoioTask CoioTask; - typedef void (*coio_func) (void *arg); - typedef unsigned long long uvlong; +typedef struct CoioTask CoioTask; +typedef void (*coio_func)(void* arg); +typedef unsigned long long uvlong; - extern CoioTask *coio_current; +extern CoioTask* coio_current; - int coio_main (); - int coio_create(const char* name, coio_func f, void *arg, unsigned int stacksize); - void coio_yield(); - uvlong coio_now(); - int coio_delay(int ms); - void coio_ready(CoioTask * task); +int coio_main(); +int coio_create(const char* name, coio_func f, void* arg, unsigned int stacksize); +void coio_yield(); +uvlong coio_now(); +int coio_delay(int ms); +void coio_ready(CoioTask* task); #ifdef __cplusplus } diff --git a/coio_glib.c b/coio_glib.c index 6e90256..e152fef 100644 --- a/coio_glib.c +++ b/coio_glib.c @@ -20,8 +20,7 @@ #include -struct coio_source -{ +struct coio_source { GSource base; }; @@ -116,8 +115,7 @@ GSource* coio_gsource_create() { coro_create(&coio_sched_ctx, NULL, NULL, NULL, 0); - static GSourceFuncs funcs = - { + static GSourceFuncs funcs = { coio_source_prepare, coio_source_check, coio_source_dispatch, diff --git a/coioimpl.h b/coioimpl.h index 1039702..2f7320b 100644 --- a/coioimpl.h +++ b/coioimpl.h @@ -25,22 +25,22 @@ struct CoioTask { coro_context ctx; struct coro_stack stk; - const char *name; + const char* name; coio_func func; - void *arg; + void* arg; uvlong timeout; int ready; int done; /* linked list support */ - CoioTask *next; - CoioTask *prev; + CoioTask* next; + CoioTask* prev; }; struct CoioTaskList { - CoioTask *head; - CoioTask *tail; + CoioTask* head; + CoioTask* tail; }; extern CoioTaskList coio_ready_list; @@ -48,8 +48,8 @@ extern CoioTaskList coio_sleeping; extern coro_context coio_sched_ctx; extern unsigned long coio_taskcount; -void coio_add (CoioTaskList * lst, CoioTask * task); -void coio_del (CoioTaskList * lst, CoioTask * task); +void coio_add(CoioTaskList* lst, CoioTask* task); +void coio_del(CoioTaskList* lst, CoioTask* task); void coio_transfer(); void coio_debug(); diff --git a/testdelay.c b/testdelay.c index eb42587..d25b491 100644 --- a/testdelay.c +++ b/testdelay.c @@ -17,7 +17,7 @@ #include "coio.h" void -_t1(void *arg) +_t1(void* arg) { printf("going to sleep 1000ms (1s)\n"); coio_delay(1000); @@ -25,7 +25,7 @@ _t1(void *arg) } int -main(int argc, char **argv) +main(int argc, char** argv) { (void) argc; (void) argv; diff --git a/testyield.c b/testyield.c index 776b357..ac1b4a2 100644 --- a/testyield.c +++ b/testyield.c @@ -17,7 +17,7 @@ #include "coio.h" void -_t1(void *arg) +_t1(void* arg) { printf("Hello 1 from _t1\n"); coio_yield(); @@ -25,7 +25,7 @@ _t1(void *arg) } void -_t2(void *arg) +_t2(void* arg) { printf("Hello 1 from _t2\n"); coio_yield(); @@ -33,7 +33,7 @@ _t2(void *arg) } int -main(int argc, char **argv) +main(int argc, char** argv) { (void) argc; (void) argv;