Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
randombit committed Jul 11, 2024
1 parent bb9c069 commit b07e4a0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
7 changes: 0 additions & 7 deletions src/lib/utils/thread_utils/thread_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ class BOTAN_TEST_API Thread_Pool final {
*/
Thread_Pool(std::optional<size_t> 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<size_t>(pool_size)) {}

~Thread_Pool() { shutdown(); }

void shutdown();
Expand Down
48 changes: 48 additions & 0 deletions src/lib/utils/thread_utils/work_fn.h
Original file line number Diff line number Diff line change
@@ -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 <functional>
#include <memory>

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<Work_Executor> 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<void()>& 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

0 comments on commit b07e4a0

Please sign in to comment.