diff --git a/src/demo/coroutine/echo_client.c b/src/demo/coroutine/echo_client.c index ec2ce195f20a5378373b693259bf4f6dfbeb259a..159cd6cc465eaa1610979a8483eaf00d1eb31686 100644 --- a/src/demo/coroutine/echo_client.c +++ b/src/demo/coroutine/echo_client.c @@ -73,6 +73,21 @@ static tb_void_t tb_demo_coroutine_echo(tb_cpointer_t priv) sock = tb_null; } +static tb_void_t tb_demo_coroutine_test_loop(tb_cpointer_t priv) +{ + tb_int_t count = 0; + while (tb_true) + { + count++; + + // trace + tb_trace_i("tb_demo_coroutine_test_loop() count = %d", count); + + // yield + tb_coroutine_yield(); + } +} + /* ////////////////////////////////////////////////////////////////////////////////////// * main */ @@ -91,6 +106,9 @@ tb_int_t tb_demo_coroutine_echo_client_main(tb_int_t argc, tb_char_t** argv) tb_co_scheduler_ref_t scheduler = tb_co_scheduler_init(); if (scheduler) { + // start test loop + tb_coroutine_start(scheduler, tb_demo_coroutine_test_loop, tb_null, 0); + // start echo tb_size_t i = 0; for (i = 0; i < count; i++) diff --git a/src/demo/coroutine/process_pipe.c b/src/demo/coroutine/process_pipe.c index 41c9e0d2ad7f34f2e891ff57a61cfdbd31eb32ad..e6068f5d6b22262a6c71f6aaab6c108d38887883 100644 --- a/src/demo/coroutine/process_pipe.c +++ b/src/demo/coroutine/process_pipe.c @@ -27,7 +27,7 @@ static tb_void_t tb_demo_coroutine_proc(tb_cpointer_t priv) { // init process tb_process_attr_t attr = {0}; - attr.outpipe = file[1]; + attr.out.pipe = file[1]; attr.outtype = TB_PROCESS_REDIRECT_TYPE_PIPE; tb_process_ref_t process = tb_process_init(argv[1], (tb_char_t const**)(argv + 1), &attr); if (process) diff --git a/src/demo/coroutine/stackless/echo_client.c b/src/demo/coroutine/stackless/echo_client.c index 014cafe83311706b2fa56e03b45e02601a5ecb09..733c0a7133895639b6093f210fc956e312c5edb8 100644 --- a/src/demo/coroutine/stackless/echo_client.c +++ b/src/demo/coroutine/stackless/echo_client.c @@ -134,6 +134,22 @@ static tb_void_t tb_demo_lo_coroutine_echo(tb_lo_coroutine_ref_t coroutine, tb_c } } +static tb_void_t tb_demo_lo_coroutine_test_loop(tb_lo_coroutine_ref_t coroutine, tb_cpointer_t priv) +{ + // enter coroutine + tb_lo_coroutine_enter(coroutine) + { + while (tb_true) + { + // trace + tb_trace_i("tb_demo_lo_coroutine_test_loop()"); + + // yield + tb_lo_coroutine_yield(); + } + } +} + /* ////////////////////////////////////////////////////////////////////////////////////// * main */ @@ -149,6 +165,9 @@ tb_int_t tb_demo_lo_coroutine_echo_client_main(tb_int_t argc, tb_char_t** argv) tb_lo_scheduler_ref_t scheduler = tb_lo_scheduler_init(); if (scheduler) { + // start test loop + tb_lo_coroutine_start(scheduler, tb_demo_lo_coroutine_test_loop, tb_null, tb_null); + // start echo tb_size_t i = 0; for (i = 0; i < count; i++) diff --git a/src/demo/coroutine/stackless/process_pipe.c b/src/demo/coroutine/stackless/process_pipe.c index e4df6bac22f925f11a381976b4a9bde022412bf5..98578d4b249f93fad8a2725fc71c8360e410b9c3 100644 --- a/src/demo/coroutine/stackless/process_pipe.c +++ b/src/demo/coroutine/stackless/process_pipe.c @@ -55,7 +55,7 @@ static tb_void_t tb_demo_lo_coroutine_func(tb_lo_coroutine_ref_t coroutine, tb_c if (tb_pipe_file_init_pair(process->file, 0)) { // init process - process->attr.outpipe = process->file[1]; + process->attr.out.pipe = process->file[1]; process->attr.outtype = TB_PROCESS_REDIRECT_TYPE_PIPE; process->proc = tb_process_init(process->argv[1], (tb_char_t const**)(process->argv + 1), &process->attr); if (process->proc) diff --git a/src/tbox/coroutine/impl/scheduler_io.c b/src/tbox/coroutine/impl/scheduler_io.c index 56bdccc804062ce17cabb6c0a7f39be6a8cf9a60..1e913f4e71db51d274fbcaac5f3b473c08ff5a56 100644 --- a/src/tbox/coroutine/impl/scheduler_io.c +++ b/src/tbox/coroutine/impl/scheduler_io.c @@ -233,6 +233,13 @@ static tb_void_t tb_co_scheduler_io_loop(tb_cpointer_t priv) { // spak timer if (!tb_co_scheduler_io_timer_spak(scheduler_io)) break; + + // check io events + if (tb_poller_wait(poller, tb_co_scheduler_io_events, 0) < 0) + { + tb_trace_e("loop: check poller failed!"); + break; + } } // no more suspended coroutines? loop end diff --git a/src/tbox/coroutine/impl/stackless/scheduler_io.c b/src/tbox/coroutine/impl/stackless/scheduler_io.c index 9412c4265cd20c3e5397f0a61e53ed813bad64ec..9ef1498efc318f15e83874cb79a8afd252d022de 100644 --- a/src/tbox/coroutine/impl/stackless/scheduler_io.c +++ b/src/tbox/coroutine/impl/stackless/scheduler_io.c @@ -271,6 +271,8 @@ static tb_void_t tb_lo_scheduler_io_loop(tb_lo_coroutine_ref_t coroutine, tb_cpo // spak timer if (!tb_lo_scheduler_io_timer_spak(scheduler_io)) break; #endif + // check io events + if (tb_poller_wait(scheduler_io->poller, tb_lo_scheduler_io_events, 0) < 0) break; } // no more suspended coroutines? loop end