| 75 | } |
| 76 | |
| 77 | inline auto enqueueCoroutine(int priority) noexcept { |
| 78 | class Awaiter { |
| 79 | public: |
| 80 | Awaiter(ThreadPool* pool, int priority) : mPool{pool}, mPriority{priority} {} |
| 81 | |
| 82 | bool await_ready() const noexcept { return false; } |
| 83 | |
| 84 | // Suspend and enqueue coroutine continuation onto the threadpool |
| 85 | void await_suspend(std::coroutine_handle<> coroutine) noexcept { mPool->enqueueTask(coroutine, mPriority); } |
| 86 | |
| 87 | void await_resume() const noexcept {} |
| 88 | |
| 89 | private: |
| 90 | ThreadPool* mPool; |
| 91 | int mPriority; |
| 92 | }; |
| 93 | |
| 94 | return Awaiter{this, priority}; |
| 95 | } |
| 96 | |
| 97 | template <TaskCoroutine F> auto enqueueCoroutine(F&& fun, int priority) -> std::invoke_result_t<F> { |
| 98 | // Nesting without capture is necessary for coroutine state to be properly put on the heap (the lambda object itself goes out of |
no outgoing calls
no test coverage detected