diff --git a/deps/.package b/deps/.package index 42fe058..85e63b9 100644 --- a/deps/.package +++ b/deps/.package @@ -1,4 +1,4 @@ -import github.com/tidwall/sco v0.1.1 +import github.com/tidwall/sco v0.2.0 sum ad1e36373245380b0f5588c11f1a69369171436a sco.c sum 92baa4119d14dbb2b1effcd2eaeb4adcba8befc1 sco.h diff --git a/deps/sco.c b/deps/sco.c index c50ffc5..afc650e 100644 --- a/deps/sco.c +++ b/deps/sco.c @@ -1854,11 +1854,11 @@ static void sco_entry(void *udata) { co->prev = co; co->next = co; if (sco_cur) { - // Reschedule the coroutine that started this one - sco_list_push_back(&sco_yielders, co); - sco_list_push_back(&sco_yielders, sco_cur); - sco_nyielders += 2; - sco_switch(false, false); + // Reschedule the coroutine that started this one immediately after + // all running coroutines, but before any yielding coroutines, and + // continue running the started coroutine. + sco_list_push_back(&sco_runners, sco_cur); + sco_nrunners++; } sco_cur = co; if (sco_user_entry) { diff --git a/neco.c b/neco.c index 919793d..fb36106 100644 --- a/neco.c +++ b/neco.c @@ -2000,11 +2000,11 @@ static void sco_entry(void *udata) { co->prev = co; co->next = co; if (sco_cur) { - // Reschedule the coroutine that started this one - sco_list_push_back(&sco_yielders, co); - sco_list_push_back(&sco_yielders, sco_cur); - sco_nyielders += 2; - sco_switch(false, false); + // Reschedule the coroutine that started this one immediately after + // all running coroutines, but before any yielding coroutines, and + // continue running the started coroutine. + sco_list_push_back(&sco_runners, sco_cur); + sco_nrunners++; } sco_cur = co; if (sco_user_entry) { diff --git a/tests/test_basic.c b/tests/test_basic.c index fd8d28f..e6885e0 100644 --- a/tests/test_basic.c +++ b/tests/test_basic.c @@ -96,14 +96,14 @@ void co_sched1(int argc, void *argv[]) { int *i = argv[1]; a[(*i)++] = 'B'; assert(neco_yield() == NECO_OK); - a[(*i)++] = 'D'; + a[(*i)++] = 'F'; } void co_sched2(int argc, void *argv[]) { assert(argc == 2); char *a = argv[0]; int *i = argv[1]; - a[(*i)++] = 'E'; + a[(*i)++] = 'D'; assert(neco_yield() == NECO_OK); a[(*i)++] = 'G'; } @@ -116,7 +116,7 @@ void co_sched(int argc, void *argv[]) { assert(neco_start(co_sched1, 2, a, i) == NECO_OK); a[(*i)++] = 'C'; assert(neco_start(co_sched2, 2, a, i) == NECO_OK); - a[(*i)++] = 'F'; + a[(*i)++] = 'E'; assert(neco_yield() == NECO_OK); a[(*i)++] = 'H'; } diff --git a/tests/test_sync.c b/tests/test_sync.c index 8aa7436..8aa6fe1 100644 --- a/tests/test_sync.c +++ b/tests/test_sync.c @@ -343,30 +343,6 @@ void test_sync_cond_deadline(void) { expect(neco_start(co_sync_cond_deadline, 0), NECO_OK); } -void co_sync_mutex_rw_order_child2(int argc, void *argv[]) { - assert(argc == 2); - neco_mutex *mu = argv[0]; - struct order *order = argv[1]; - order_add(order, 17); - expect(neco_mutex_rdlock(mu), NECO_OK); - order_add(order, 23); - expect(neco_mutex_unlock(mu), NECO_OK); - order_add(order, 26); -} - -void co_sync_mutex_rw_order_child3(int argc, void *argv[]) { - assert(argc == 2); - neco_mutex *mu = argv[0]; - struct order *order = argv[1]; - order_add(order, 19); - expect(neco_mutex_trylock(mu), NECO_BUSY); - order_add(order, 20); - expect(neco_mutex_rdlock(mu), NECO_OK); - order_add(order, 24); - expect(neco_mutex_unlock(mu), NECO_OK); - order_add(order, 27); -} - void co_sync_mutex_rw_order_child(int argc, void *argv[]) { assert(argc == 2); neco_mutex *mu = argv[0]; @@ -382,12 +358,6 @@ void co_sync_mutex_rw_order_child(int argc, void *argv[]) { order_add(order, 13); expect(neco_yield(), NECO_OK); order_add(order, 14); - expect(neco_start(co_sync_mutex_rw_order_child2, 2, mu, order), NECO_OK); - order_add(order, 18); - expect(neco_start(co_sync_mutex_rw_order_child3, 2, mu, order), NECO_OK); - order_add(order, 21); - expect(neco_mutex_unlock(mu), NECO_OK); - order_add(order, 28); } void co_sync_mutex_rw_order(int argc, void *argv[]) { @@ -414,15 +384,6 @@ void co_sync_mutex_rw_order(int argc, void *argv[]) { order_add(&order, 12); expect(neco_mutex_unlock(mu), NECO_OK); order_add(&order, 15); - expect(neco_mutex_tryrdlock(mu), NECO_BUSY); - order_add(&order, 16); - expect(neco_mutex_rdlock(mu), NECO_OK); - order_add(&order, 22); - expect(neco_mutex_unlock(mu), NECO_OK); - order_add(&order, 25); - expect(neco_yield(), NECO_OK); - order_add(&order, 29); - expect(neco_mutex_destroy(mu), NECO_OK); order_check(&order); }