-
Notifications
You must be signed in to change notification settings - Fork 569
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
48 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |