Skip to content

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

Name
virtual~IConcurrencyProvider() =default
virtual voidnotifyWorkAvailable(WorkContractGroup * group =nullptr) =0
Notifies the provider that work may be available.
virtual voidnotifyMainThreadWorkAvailable(WorkContractGroup * group =nullptr)
Notifies the provider that main thread work may be available.
virtual voidnotifyGroupDestroyed(WorkContractGroup * group) =0
Called when a group is being destroyed.
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 provider
class 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);
}
};
virtual ~IConcurrencyProvider() =default
virtual void notifyWorkAvailable(
WorkContractGroup * group =nullptr
) =0

Notifies 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.

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);
}
virtual void notifyGroupDestroyed(
WorkContractGroup * group
) =0

Called 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