diff options
author | Keuin <[email protected]> | 2022-04-20 00:48:44 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2022-04-20 00:48:44 +0800 |
commit | ba97aeb0a6ff52b79f43f883c639a55c8e3cf78d (patch) | |
tree | 8f8707eba7095a75c6d65d7265d1b8b8040c2194 /threading.h | |
parent | 3fa4d41e9cac75df7514c2ff8dd27842aaafc4a7 (diff) |
Reserve vector thread_pool::tasks to speed up task initializing.
Diffstat (limited to 'threading.h')
-rw-r--r-- | threading.h | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/threading.h b/threading.h index 6d79494..249a115 100644 --- a/threading.h +++ b/threading.h @@ -41,9 +41,12 @@ class thread_pool { void worker_main(); public: - explicit thread_pool(unsigned thread_count, const U &shared_ctx, V &mut_shared_ctx) : + thread_pool(unsigned thread_count, const U &shared_ctx, V &mut_shared_ctx, size_t reserve_tasks = -1) : thread_count{thread_count}, shared_ctx{shared_ctx}, mut_shared_ctx{mut_shared_ctx} { std::cerr << "Using " << (counter.is_lock_free() ? "lock-free" : "locking") << " dispatcher." << std::endl; + if (reserve_tasks > 0) { + tasks.reserve(reserve_tasks); + } } // Thread unsafe! |