From b86b7f9b29928c8b68ed06430b493bf932a16af0 Mon Sep 17 00:00:00 2001 From: q66 Date: Sun, 26 Mar 2017 14:38:39 +0200 Subject: [PATCH] allow setting the thread count for coroutine scheduler --- ostd/concurrency.hh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ostd/concurrency.hh b/ostd/concurrency.hh index e673f0d..5dc14b4 100644 --- a/ostd/concurrency.hh +++ b/ostd/concurrency.hh @@ -474,8 +474,10 @@ private: }; public: - basic_coroutine_scheduler(SA &&sa = SA{}): - p_stacks(std::move(sa)) + basic_coroutine_scheduler( + size_t thrs = std::thread::hardware_concurrency(), SA &&sa = SA{} + ): + p_threads(thrs), p_stacks(std::move(sa)) {} ~basic_coroutine_scheduler() {} @@ -593,7 +595,7 @@ private: } void init() { - size_t size = std::thread::hardware_concurrency(); + size_t size = p_threads; std::vector thrs; thrs.reserve(size); for (size_t i = 0; i < size; ++i) { @@ -682,6 +684,7 @@ private: } } + size_t p_threads; std::condition_variable p_cond; std::mutex p_lock; SA p_stacks;