From ac53e701b1f0d7558d59c710856cf1b705c2d0bd Mon Sep 17 00:00:00 2001 From: wangkun Date: Fri, 16 Jul 2021 11:27:27 +0800 Subject: [PATCH 1/4] fix demo[coroutine_process_pipe] compilation errors --- src/demo/coroutine/process_pipe.c | 2 +- src/demo/coroutine/stackless/process_pipe.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/demo/coroutine/process_pipe.c b/src/demo/coroutine/process_pipe.c index 41c9e0d2..e6068f5d 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/process_pipe.c b/src/demo/coroutine/stackless/process_pipe.c index e4df6bac..98578d4b 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) -- Gitee From a129705a61c7149769c28c1702aabf01c6863039 Mon Sep 17 00:00:00 2001 From: wangkun Date: Fri, 16 Jul 2021 14:27:42 +0800 Subject: [PATCH 2/4] fix io scheduler error --- src/demo/coroutine/echo_client.c | 18 ++++++++++++++++++ src/demo/coroutine/stackless/echo_client.c | 19 +++++++++++++++++++ src/tbox/coroutine/impl/scheduler_io.c | 7 +++++++ .../coroutine/impl/stackless/scheduler_io.c | 2 ++ 4 files changed, 46 insertions(+) diff --git a/src/demo/coroutine/echo_client.c b/src/demo/coroutine/echo_client.c index ec2ce195..159cd6cc 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/stackless/echo_client.c b/src/demo/coroutine/stackless/echo_client.c index 014cafe8..733c0a71 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/tbox/coroutine/impl/scheduler_io.c b/src/tbox/coroutine/impl/scheduler_io.c index 56bdccc8..7452e5db 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 9412c426..9ef1498e 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 -- Gitee From 0746b1d1dda95e1168c865508d0766f3a82303ea Mon Sep 17 00:00:00 2001 From: wangkun Date: Wed, 4 Aug 2021 10:36:54 +0800 Subject: [PATCH 3/4] =?UTF-8?q?TAB=E8=BD=AC=E7=A9=BA=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tbox/coroutine/impl/scheduler_io.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/tbox/coroutine/impl/scheduler_io.c b/src/tbox/coroutine/impl/scheduler_io.c index 7452e5db..27c52983 100644 --- a/src/tbox/coroutine/impl/scheduler_io.c +++ b/src/tbox/coroutine/impl/scheduler_io.c @@ -235,11 +235,11 @@ static tb_void_t tb_co_scheduler_io_loop(tb_cpointer_t priv) 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; - } + 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 -- Gitee From 0e2b1c397137220e8dbfb3e9e315bbabdae14e3c Mon Sep 17 00:00:00 2001 From: wangkun Date: Wed, 4 Aug 2021 10:39:04 +0800 Subject: [PATCH 4/4] =?UTF-8?q?TAB=E8=BD=AC=E7=A9=BA=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tbox/coroutine/impl/scheduler_io.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/tbox/coroutine/impl/scheduler_io.c b/src/tbox/coroutine/impl/scheduler_io.c index 27c52983..1e913f4e 100644 --- a/src/tbox/coroutine/impl/scheduler_io.c +++ b/src/tbox/coroutine/impl/scheduler_io.c @@ -235,11 +235,11 @@ static tb_void_t tb_co_scheduler_io_loop(tb_cpointer_t priv) 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; - } + 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 -- Gitee