Am 11.04.2019 um 19:27 hat Vladimir Sementsov-Ogievskiy geschrieben: > Introduce a function to gracefully wake-up a coroutine, sleeping in > qemu_co_sleep_ns() sleep. > > Signed-off-by: Vladimir Sementsov-Ogievskiy <vsement...@virtuozzo.com>
You can simply reenter the coroutine while it has yielded in qemu_co_sleep_ns(). This is supported. I think what you add here is just the condition that you wake up the coroutine only if it's currently sleeping, but not when it has yielded for other reasons. This suggests that you're trying to reenter a coroutine of which you don't know where exactly in its code it currently is. This is wrong. Just knowing that it's sleeping doesn't tell you where the coroutine is. It could have called a function that sleeps internally and must not be woken up early. If you reenter a coroutine, you always must know the exact point where it yielded (or in exceptional cases, the exact points (plural)). Just reentering because it sleeps will wake it up in unexpected places, generally speaking. So I don't think this function is a good idea. It's too easy to misuse, and if you don't misuse it, you can directly call aio_co_wake(). Kevin