yield current task in single-threaded coroutine scheduler on spawn

This schedules tasks more aggressively, letting side tasks always run.
master
Daniel Kolesa 2017-11-05 22:09:28 +01:00
parent 67525af4e5
commit ec9ddb2aad
1 changed files with 11 additions and 7 deletions

View File

@ -461,13 +461,16 @@ struct basic_thread_scheduler: scheduler {
}
void do_spawn(std::function<void()> func) {
std::lock_guard<std::mutex> l{p_lock};
p_threads.emplace_front();
auto it = p_threads.begin();
*it = std::thread{[this, it, lfunc = std::move(func)]() {
lfunc();
remove_thread(it);
}};
{
std::lock_guard<std::mutex> l{p_lock};
p_threads.emplace_front();
auto it = p_threads.begin();
*it = std::thread{[this, it, lfunc = std::move(func)]() {
lfunc();
remove_thread(it);
}};
}
yield();
}
void yield() noexcept {
@ -719,6 +722,7 @@ public:
void do_spawn(std::function<void()> func) {
p_coros.emplace_back(std::move(func), p_stacks.get_allocator());
yield();
}
void yield() noexcept {