diff options
author | Håvard Pettersen <havardpe@yahooinc.com> | 2022-11-30 13:31:53 +0000 |
---|---|---|
committer | Håvard Pettersen <havardpe@yahooinc.com> | 2022-11-30 13:31:53 +0000 |
commit | 43e975f7c66a029e399c37f1c2f92880c5350b94 (patch) | |
tree | bab82cde6b34e602813b3b449d44c156f0360bfd /vespalib | |
parent | c6a6f02c8218b677b2af737c6809db384450e2a4 (diff) |
avoid race caused by using 'accepted' after destruction
also tag await_suspend functions with noinline to make sure clang does
not put local variables into the coroutine state (this was only an
issue for try_schedule).
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/vespa/vespalib/coro/schedule.h | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/vespalib/src/vespa/vespalib/coro/schedule.h b/vespalib/src/vespa/vespalib/coro/schedule.h index 71a384f356f..fc589d65a43 100644 --- a/vespalib/src/vespa/vespalib/coro/schedule.h +++ b/vespalib/src/vespa/vespalib/coro/schedule.h @@ -22,7 +22,7 @@ auto schedule(Executor &executor) { awaiter(Executor &executor_in) : executor(executor_in) {} bool await_ready() const noexcept { return false; } - void await_suspend(std::coroutine_handle<> handle) { + void await_suspend(std::coroutine_handle<> handle) __attribute__((noinline)) { struct ResumeTask : Executor::Task { std::coroutine_handle<> handle; ResumeTask(std::coroutine_handle<> handle_in) @@ -52,7 +52,7 @@ auto try_schedule(Executor &executor) { awaiter(Executor &executor_in) : executor(executor_in), accepted(true) {} bool await_ready() const noexcept { return false; } - bool await_suspend(std::coroutine_handle<> handle) { + bool await_suspend(std::coroutine_handle<> handle) __attribute__((noinline)) { struct ResumeTask : Executor::Task { std::coroutine_handle<> handle; ResumeTask(std::coroutine_handle<> handle_in) @@ -66,8 +66,9 @@ auto try_schedule(Executor &executor) { // with handle.resume() from executor thread before // await_suspend has returned. accepted = false; + return false; } - return accepted; + return true; } [[nodiscard]] bool await_resume() const noexcept { return accepted; } }; |