From b07e4a0a4cd184c15ddb7bc1d137fd7071416a64 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Thu, 11 Jul 2024 17:42:40 -0400 Subject: [PATCH] wip --- src/lib/utils/thread_utils/thread_pool.h | 7 ---- src/lib/utils/thread_utils/work_fn.h | 48 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 src/lib/utils/thread_utils/work_fn.h diff --git a/src/lib/utils/thread_utils/thread_pool.h b/src/lib/utils/thread_utils/thread_pool.h index 9673efebc13..62b028a81b6 100644 --- a/src/lib/utils/thread_utils/thread_pool.h +++ b/src/lib/utils/thread_utils/thread_pool.h @@ -38,13 +38,6 @@ class BOTAN_TEST_API Thread_Pool final { */ Thread_Pool(std::optional pool_size); - /** - * Initialize a thread pool with some number of threads - * @param pool_size number of threads in the pool, if 0 - * then some default value is chosen. - */ - Thread_Pool(size_t pool_size = 0) : Thread_Pool(std::optional(pool_size)) {} - ~Thread_Pool() { shutdown(); } void shutdown(); diff --git a/src/lib/utils/thread_utils/work_fn.h b/src/lib/utils/thread_utils/work_fn.h new file mode 100644 index 00000000000..dbf84338c10 --- /dev/null +++ b/src/lib/utils/thread_utils/work_fn.h @@ -0,0 +1,48 @@ +/* +* (C) 2024 Jack Lloyd +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#ifndef BOTAN_WORK_FN_H_ +#define BOTAN_WORK_FN_H_ + +#include +#include + +namespace Botan { + +/** +* A Work Executor is something capable of executing functions +* +* The library delegates certain work +*/ +class Work_Executor { + public: + /** + * Set the global work executor. This allows for example + * providing a custom thread pool. + */ + static void set_global_work_executor(std::shared_ptr worker); + + virtual ~Work_Executor() = default; + + /** + * The work executor promises to eventually call fn + * + * The execution may be delayed and in any order + */ + virtual void run_work(const std::function& fn) = 0; + + /** + * Return a best-effort approximation of how much parallelism is + * possible + */ + virtual size_t available_parallelism() const = 0; + + worker_count() const { return m_workers.size(); } +}; + +} + +#endif