hnes / libaco

A blazing fast and lightweight C asymmetric coroutine library 💎 ⛅🚀⛅🌞
https://libaco.org
Apache License 2.0
3.49k stars 392 forks source link

Add aco_yield_to() #32

Open AltraMayor opened 4 years ago

AltraMayor commented 4 years ago

This pull request introduces aco_yield_to() that enables a non-main co to yield to another co with a single context switch.

The first patch, namely add aco_yield_to(), seems a little complicated because part of the code of aco_resume() is moved to a new auxiliary function called aco_own_stack() to avoid duplicating code at aco_yield_to(). Ignoring this code movement, the additions are straightforward.

The second patch adds test_aco_tutorial_7.c to test and show how to use aco_yield_to().

This pull request closes #31