Diligent Engine
Loading...
Searching...
No Matches
Diligent::IAsyncTask Struct Referenceabstract

Asynchronous task interface. More...

#include <ThreadPool.h>

Inheritance diagram for Diligent::IAsyncTask:
Diligent.IObject

Public Member Functions

virtual ASYNC_TASK_STATUS DILIGENT_CALL_TYPE Run (Uint32 ThreadId)=0
 Run the asynchronous task.
virtual void DILIGENT_CALL_TYPE Cancel ()=0
 Requests task cancellation, if possible.
virtual void DILIGENT_CALL_TYPE SetStatus (ASYNC_TASK_STATUS TaskStatus)=0
 Sets the task status, see Diligent::ASYNC_TASK_STATUS.
virtual ASYNC_TASK_STATUS DILIGENT_CALL_TYPE GetStatus () const =0
 Gets the task status, see Diligent::ASYNC_TASK_STATUS.
virtual void DILIGENT_CALL_TYPE SetPriority (float fPriority)=0
 Sets the task priority.
virtual float DILIGENT_CALL_TYPE GetPriority () const =0
 Returns the task priority.
virtual bool DILIGENT_CALL_TYPE IsFinished () const =0
 Checks if the task is finished (i.e. cancelled or complete).
virtual void DILIGENT_CALL_TYPE WaitForCompletion () const =0
 Waits until the task is complete.
virtual void DILIGENT_CALL_TYPE WaitUntilRunning () const =0
 Waits until the task leaves the Diligent::ASYNC_TASK_STATUS_NOT_STARTED state.
Public Member Functions inherited from Diligent.IObject
virtual void DILIGENT_CALL_TYPE QueryInterface (const INTERFACE_ID &IID, IObject **ppInterface)=0
 Queries the specific interface.
template<typename DerivedType, typename = typename std::enable_if<std::is_base_of<IObject, DerivedType>::value>::type>
void QueryInterface (const INTERFACE_ID &IID, DerivedType **ppInterface)
virtual ReferenceCounterValueType DILIGENT_CALL_TYPE AddRef ()=0
 Increments the number of strong references by 1.
virtual ReferenceCounterValueType DILIGENT_CALL_TYPE Release ()=0
virtual IReferenceCounters *DILIGENT_CALL_TYPE GetReferenceCounters () const =0

Detailed Description

Asynchronous task interface.

Member Function Documentation

◆ Cancel()

virtual void DILIGENT_CALL_TYPE Diligent::IAsyncTask::Cancel ( )
pure virtual

Requests task cancellation, if possible.

This is a cooperative cancellation request. If the task is running, the task implementation should observe the request and abort execution, if possible. Calling this method does not remove the task from a thread pool queue and does not guarantee that a task in the Diligent::ASYNC_TASK_STATUS_NOT_STARTED state immediately transitions to Diligent::ASYNC_TASK_STATUS_CANCELLED.

To cancel a queued task that has not started, use IThreadPool::RemoveTask().

◆ Run()

virtual ASYNC_TASK_STATUS DILIGENT_CALL_TYPE Diligent::IAsyncTask::Run ( Uint32 ThreadId)
pure virtual

Run the asynchronous task.

Parameters
[in]ThreadId- Id of the thread that is running this task.

Before starting the task, the thread pool sets its status to Diligent::ASYNC_TASK_STATUS_RUNNING.

The method must return one of the following values:

The thread pool will set the task status to the returned value after the Run() method completes. This way if the GetStatus() method returns any value other than Diligent::ASYNC_TASK_STATUS_RUNNING, it is guaranteed that the task is not executed by any thread.

◆ SetPriority()

virtual void DILIGENT_CALL_TYPE Diligent::IAsyncTask::SetPriority ( float fPriority)
pure virtual

Sets the task priority.

NaN priority is invalid. Implementations will report an error and use the default priority 0 instead.

◆ WaitForCompletion()

virtual void DILIGENT_CALL_TYPE Diligent::IAsyncTask::WaitForCompletion ( ) const
pure virtual

Waits until the task is complete.

Note
This method must not be called from the same thread that is running the task or a deadlock will occur.

◆ WaitUntilRunning()

virtual void DILIGENT_CALL_TYPE Diligent::IAsyncTask::WaitUntilRunning ( ) const
pure virtual

Waits until the task leaves the Diligent::ASYNC_TASK_STATUS_NOT_STARTED state.

When this method returns, the task may be running, complete, or cancelled. A fast task may reach Diligent::ASYNC_TASK_STATUS_COMPLETE before the waiting thread wakes up, so this method does not guarantee that the task is still running when it returns.

Warning
An application is responsible to make sure that tasks currently in the queue will eventually finish or otherwise leave the Diligent::ASYNC_TASK_STATUS_NOT_STARTED state.

This method must not be called from the worker thread.