CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::AppleDispatchQueue Class Reference

Abstracts a libdispatch queue as an ASIO execution context. More...

#include <CeresEngine/Platform/Apple/AppleDispatchQueue.hpp>

Inheritance diagram for CeresEngine::AppleDispatchQueue:
CeresEngine::DispatchQueue CeresEngine::ExecutionContext

Classes

class  Executor
 An executor object that dispatches calls to a libdispatch queue. More...
 

Public Types

using executor_type = Executor
 An executor object that dispatches calls to a libdispatch queue.
 
- Public Types inherited from CeresEngine::ExecutionContext
using ID = id
 
using executor_type = AnyExecutor
 

Public Member Functions

 AppleDispatchQueue (const String &name, DispatchQueueType type, AppleDispatchQueue *const queue=nullptr) noexcept
 Creates a new Apple queue instance.
 
 AppleDispatchQueue (dispatch_queue_t queue, DispatchQueueType type) noexcept
 Creates a new Apple queue from an existing dispatch_queue_t object.
 
 ~AppleDispatchQueue () noexcept override
 Destructor shuts down the dispatch queue.
 
AnyExecutor getExecutor () noexcept final
 Returns an executor that run execute scheduled commands on the context.
 
void suspend () final
 Suspends the invocation of function objects on a queue.
 
void resume () final
 Resumes the invocation of block objects on a queue.
 
UPtr< DispatchQueuecreateSubQueue (DispatchQueueType type, StringView name="") final
 Resumes the invocation of block objects on a queue.
 
dispatch_queue_t getDispatchQueue () const noexcept
 The dispatch_queue_t instance to execute commands on.
 
executor_type get_executor () noexcept
 Returns an executor that run execute scheduled commands on the context.
 
- Public Member Functions inherited from CeresEngine::ExecutionContext
virtual ~ExecutionContext () noexcept=default
 Virtual destructor for the execution context object.
 
template<typename T >
bool hasService () noexcept
 Determine if the ExecutionContext contains the specified service type.
 
template<typename T >
TgetService () noexcept
 Obtain the service object corresponding to the given type.
 
template<typename T >
TgetServiceIf () noexcept
 Obtain the service object corresponding to the given type.
 
executor_type get_executor () noexcept
 Returns an executor that run execute scheduled commands on the context.
 
bool isActive () const noexcept
 Checks if the execution context is currently active.
 

Private Member Functions

void onWorkStarted () noexcept
 Inform the executor that it has some outstanding work to do.
 
void onWorkFinished () noexcept
 Inform the executor that some work is no longer outstanding.
 
void schedule (UniqueFunction< void()> function, ExecutorBlocking blockingProperty, ExecutorPriority priority)
 Schedules a new function to be run in the run loop.
 

Private Attributes

dispatch_queue_t mQueue
 The dispatch_queue_t instance to execute commands on.
 
DispatchQueueType mType
 Determines the type of dispatch queue.
 

Additional Inherited Members

- Static Public Member Functions inherited from CeresEngine::ExecutionContext
static ExecutionContextgetCurrent () noexcept
 Gets the current execution context, if any is active.
 
static ExecutionContextget () noexcept
 Gets the current execution context, if any is active.
 

Detailed Description

Abstracts a libdispatch queue as an ASIO execution context.

Member Typedef Documentation

◆ executor_type

An executor object that dispatches calls to a libdispatch queue.

Constructor & Destructor Documentation

◆ AppleDispatchQueue() [1/2]

CeresEngine::AppleDispatchQueue::AppleDispatchQueue ( const String name,
DispatchQueueType  type,
AppleDispatchQueue *const  queue = nullptr 
)
explicitnoexcept

Creates a new Apple queue instance.

Parameters
nameThe queue name. Can be an empty string.
typeThe queue type, either concurrent or serial.
queueThe target queue. If defined, the created queue will delegate work to this queue.

◆ AppleDispatchQueue() [2/2]

CeresEngine::AppleDispatchQueue::AppleDispatchQueue ( dispatch_queue_t  queue,
DispatchQueueType  type 
)
explicitnoexcept

Creates a new Apple queue from an existing dispatch_queue_t object.

◆ ~AppleDispatchQueue()

CeresEngine::AppleDispatchQueue::~AppleDispatchQueue ( )
overridenoexcept

Destructor shuts down the dispatch queue.

Member Function Documentation

◆ createSubQueue()

UPtr< DispatchQueue > CeresEngine::AppleDispatchQueue::createSubQueue ( DispatchQueueType  type,
StringView  name = "" 
)
finalvirtual

Resumes the invocation of block objects on a queue.

Calling this function decrements the suspension count of a suspended queue. While the count is greater than zero, the queue remains suspended. When the suspension count returns to zero, any blocks submitted to the dispatch queue or any events observed by the dispatch source while suspended are delivered.

With one exception, each call to resume() must balance a call to suspend(). It is undefined to call resume() more times than suspend(), which would result in a negative suspension count.

Implements CeresEngine::DispatchQueue.

◆ get_executor()

AppleDispatchQueue::Executor CeresEngine::AppleDispatchQueue::get_executor ( )
inlinenoexcept

Returns an executor that run execute scheduled commands on the context.

◆ getDispatchQueue()

dispatch_queue_t CeresEngine::AppleDispatchQueue::getDispatchQueue ( ) const
inlinenoexcept

The dispatch_queue_t instance to execute commands on.

◆ getExecutor()

AnyExecutor CeresEngine::AppleDispatchQueue::getExecutor ( )
inlinefinalvirtualnoexcept

Returns an executor that run execute scheduled commands on the context.

Implements CeresEngine::ExecutionContext.

◆ onWorkFinished()

void CeresEngine::AppleDispatchQueue::onWorkFinished ( )
privatenoexcept

Inform the executor that some work is no longer outstanding.

◆ onWorkStarted()

void CeresEngine::AppleDispatchQueue::onWorkStarted ( )
privatenoexcept

Inform the executor that it has some outstanding work to do.

◆ resume()

void CeresEngine::AppleDispatchQueue::resume ( )
finalvirtual

Resumes the invocation of block objects on a queue.

Calling this function decrements the suspension count of a suspended queue. While the count is greater than zero, the queue remains suspended. When the suspension count returns to zero, any blocks submitted to the dispatch queue or any events observed by the dispatch source while suspended are delivered.

With one exception, each call to resume() must balance a call to suspend(). It is undefined to call resume() more times than suspend(), which would result in a negative suspension count.

Implements CeresEngine::DispatchQueue.

◆ schedule()

void CeresEngine::AppleDispatchQueue::schedule ( UniqueFunction< void()>  function,
ExecutorBlocking  blockingProperty,
ExecutorPriority  priority 
)
private

Schedules a new function to be run in the run loop.

Parameters
functionThe function to be executed.

◆ suspend()

void CeresEngine::AppleDispatchQueue::suspend ( )
finalvirtual

Suspends the invocation of function objects on a queue.

By suspending a dispatch object, your application can temporarily prevent the execution of any functions associated with that queue.

The suspension occurs after completion of any blocks running at the time of the call. Calling this function increments the suspension count of the object, and calling resume() decrements it. While the count is greater than zero, the object remains suspended, so you must balance each suspend() call with a matching resume() call.

Any blocks submitted to a dispatch queue or events observed by a dispatch source are delivered once the object is resumed.

Note
It is a programmer error to release an object that is currently suspended, because suspension implies that there is still work to be done. Therefore, always balance calls to this method with a corresponding call to resume() before disposing of the queue. The behavior when releasing the last reference to a dispatch object while it is in a suspended state is undefined.

Implements CeresEngine::DispatchQueue.

Member Data Documentation

◆ mQueue

dispatch_queue_t CeresEngine::AppleDispatchQueue::mQueue
private

The dispatch_queue_t instance to execute commands on.

◆ mType

DispatchQueueType CeresEngine::AppleDispatchQueue::mType
private

Determines the type of dispatch queue.


The documentation for this class was generated from the following file: