diff --git a/coio.cpp b/coio.cpp index 10bc4c1..33084da 100644 --- a/coio.cpp +++ b/coio.cpp @@ -82,11 +82,17 @@ _process_events() } } -int -coio_main() +void +coio_init() { /* initialize empty ctx for scheduler */ coio_sched_ctx = co_active(); +} + +int +coio_main() +{ + coio_init(); /* scheduler mainloop */ for (;;) { diff --git a/coio.h b/coio.h index ec258aa..3d726db 100644 --- a/coio.h +++ b/coio.h @@ -25,6 +25,8 @@ typedef unsigned long long uvlong; extern CoioTask* coio_current; +void +coio_init(); int coio_main(); int diff --git a/coio_glib.cpp b/coio_glib.cpp index d0a5294..728667c 100644 --- a/coio_glib.cpp +++ b/coio_glib.cpp @@ -137,7 +137,7 @@ coio_source_finalize(GSource* source) GSource* coio_gsource_create() { - coio_sched_ctx = co_active(); + coio_init(); static GSourceFuncs funcs = { coio_source_prepare, coio_source_check, diff --git a/testdelay.c b/testdelay.c index bd5c6a7..c5b4df0 100644 --- a/testdelay.c +++ b/testdelay.c @@ -17,7 +17,7 @@ #include "coio.h" void -_t1(void* arg) +_t1() { printf("going to sleep 1000ms (1s)\n"); coio_delay(1000); @@ -30,7 +30,9 @@ main(int argc, char** argv) (void) argc; (void) argv; - coio_create("t1", _t1, NULL, 0x8000); + coio_init(); + + coio_create("t1", _t1, 0x8000); if (coio_main() < 0) { printf("Deadlocked\n");