EntropyEngine::Core::Concurrency::IConcurrencyProvider
EntropyEngine::Core::Concurrency::IConcurrencyProvider
Section titled “EntropyEngine::Core::Concurrency::IConcurrencyProvider”Interface for concurrency providers that execute work from WorkContractGroups. More…
#include <IConcurrencyProvider.h>
Inherited by EntropyEngine::Core::Concurrency::WorkService
Public Functions
Section titled “Public Functions”| Name | |
|---|---|
| virtual | ~IConcurrencyProvider() =default |
| virtual void | notifyWorkAvailable(WorkContractGroup * group =nullptr) =0 Notifies the provider that work may be available. |
| virtual void | notifyMainThreadWorkAvailable(WorkContractGroup * group =nullptr) Notifies the provider that main thread work may be available. |
| virtual void | notifyGroupDestroyed(WorkContractGroup * group) =0 Called when a group is being destroyed. |
Detailed Description
Section titled “Detailed Description”class EntropyEngine::Core::Concurrency::IConcurrencyProvider;Interface for concurrency providers that execute work from WorkContractGroups.
This interface allows WorkContractGroups to notify their associated concurrency provider (like WorkService) when work becomes available, enabling efficient wake-up of waiting threads without creating direct dependencies.
Implementers of this interface are responsible for executing work from the groups they manage, and groups will call these methods to provide hints about work availability.
The key insight here is the inversion of control: instead of providers polling groups for work (inefficient), groups push notifications when work arrives. This enables sleeping threads to wake immediately when work is available, rather than spinning or using fixed sleep intervals.
Common implementations:
- WorkService: The main thread pool that manages multiple groups
- SingleThreadedProvider: Executes work on a dedicated thread (testing)
- ImmediateProvider: Executes work synchronously (debugging)
Thread safety: All methods must be thread-safe as they may be called concurrently from multiple WorkContractGroups.
// Implementing a custom providerclass MyProvider : public IConcurrencyProvider { std::condition_variable cv; std::mutex mutex;
void notifyWorkAvailable(WorkContractGroup* group) override { std::lock_guard<std::mutex> lock(mutex); cv.notify_one(); // Wake a thread to check for work }
void notifyGroupDestroyed(WorkContractGroup* group) override { // Remove from internal group list removeGroup(group); }};Public Functions Documentation
Section titled “Public Functions Documentation”function ~IConcurrencyProvider
Section titled “function ~IConcurrencyProvider”virtual ~IConcurrencyProvider() =defaultfunction notifyWorkAvailable
Section titled “function notifyWorkAvailable”virtual void notifyWorkAvailable( WorkContractGroup * group =nullptr) =0Notifies the provider that work may be available.
Parameters:
- group The group that has new work available (optional, for routing)
Reimplemented by: EntropyEngine::Core::Concurrency::WorkService::notifyWorkAvailable
Called by WorkContractGroup when new work is scheduled. The provider should wake up any waiting threads to check for work. This is just a hint - the work may have already been consumed by the time a thread wakes up.
function notifyMainThreadWorkAvailable
Section titled “function notifyMainThreadWorkAvailable”inline virtual void notifyMainThreadWorkAvailable( WorkContractGroup * group =nullptr)Notifies the provider that main thread work may be available.
Parameters:
- group The group that has new main thread work available (optional)
Called when ExecutionType::MainThread work is scheduled. Unlike regular work which worker threads grab, main thread work must be explicitly pumped by calling executeMainThreadWork(). Override to handle main thread notifications differently (e.g., post to UI event queue).
void notifyMainThreadWorkAvailable(WorkContractGroup* group) override { // Post event to UI thread's message queue PostMessage(hWnd, WM_MAIN_THREAD_WORK, 0, 0);}function notifyGroupDestroyed
Section titled “function notifyGroupDestroyed”virtual void notifyGroupDestroyed( WorkContractGroup * group) =0Called when a group is being destroyed.
Parameters:
- group The group being destroyed
Reimplemented by: EntropyEngine::Core::Concurrency::WorkService::notifyGroupDestroyed
Allows the provider to clean up any references to the group. After this call, the provider must not access the group pointer.
Updated on 2026-01-26 at 17:14:35 -0500