ScummVM API documentation
Common::CoroutineScheduler Class Reference

#include <coroutines.h>

Inheritance diagram for Common::CoroutineScheduler:
Common::Singleton< CoroutineScheduler > Common::NonCopyable

Public Types

typedef void(* VFPTRPP) (PROCESS *)
 

Public Member Functions

void reset ()
 
void schedule ()
 
void rescheduleAll ()
 
void reschedule (PPROCESS pReSchedProc=nullptr)
 
void giveWay (PPROCESS pReSchedProc=nullptr)
 
void waitForSingleObject (Common::CoroContext &coroParam, int pid, uint32 duration, bool *expired=nullptr)
 
void waitForMultipleObjects (Common::CoroContext &coroParam, int nCount, uint32 *pidList, bool bWaitAll, uint32 duration, bool *expired=nullptr)
 
void sleep (Common::CoroContext &coroParam, uint32 duration)
 
PROCESScreateProcess (uint32 pid, CORO_ADDR coroAddr, const void *pParam, int sizeParam)
 
uint32 createProcess (CORO_ADDR coroAddr, const void *pParam, int sizeParam)
 
uint32 createProcess (CORO_ADDR coroAddr, const void *pParam)
 
void killProcess (PROCESS *pKillProc)
 
PROCESSgetCurrentProcess ()
 
int getCurrentPID () const
 
int killMatchingProcess (uint32 pidKill, int pidMask=-1)
 
void setResourceCallback (VFPTRPP pFunc)
 
Event methods
uint32 createEvent (bool bManualReset, bool bInitialState)
 
void closeEvent (uint32 pidEvent)
 
void setEvent (uint32 pidEvent)
 
void resetEvent (uint32 pidEvent)
 
void pulseEvent (uint32 pidEvent)
 

Additional Inherited Members

- Static Public Member Functions inherited from Common::Singleton< CoroutineScheduler >
static bool hasInstance ()
 
static CoroutineSchedulerinstance ()
 
static void destroy ()
 
- Protected Types inherited from Common::Singleton< CoroutineScheduler >
typedef CoroutineScheduler SingletonBaseType
 
- Static Protected Attributes inherited from Common::Singleton< CoroutineScheduler >
static CoroutineScheduler_singleton
 

Detailed Description

Create and manage "processes" (really coroutines).

Member Typedef Documentation

◆ VFPTRPP

typedef void(* Common::CoroutineScheduler::VFPTRPP) (PROCESS *)

Pointer to a function of the form "void function(PPROCESS)"

Member Function Documentation

◆ reset()

void Common::CoroutineScheduler::reset ( )

Kill all processes and place them on the free list.

◆ schedule()

void Common::CoroutineScheduler::schedule ( )

Give all active processes a chance to run.

◆ rescheduleAll()

void Common::CoroutineScheduler::rescheduleAll ( )

Reschedule all processes to run again this tick.

◆ reschedule()

void Common::CoroutineScheduler::reschedule ( PPROCESS  pReSchedProc = nullptr)

If the specified process has already run on this tick, make it run again on the current tick.

◆ giveWay()

void Common::CoroutineScheduler::giveWay ( PPROCESS  pReSchedProc = nullptr)

Move the specified process to the end of the dispatch queue allowing it to run again within the current game cycle.

Parameters
pReSchedProcThe process to move.

◆ waitForSingleObject()

void Common::CoroutineScheduler::waitForSingleObject ( Common::CoroContext coroParam,
int  pid,
uint32  duration,
bool *  expired = nullptr 
)

Continuously make a given process wait for another process to finish or event to signal.

Parameters
pidProcess/Event identifier.
durationDuration in milliseconds.
expiredIf specified, set to true if the delay period expired.

◆ waitForMultipleObjects()

void Common::CoroutineScheduler::waitForMultipleObjects ( Common::CoroContext coroParam,
int  nCount,
uint32 *  pidList,
bool  bWaitAll,
uint32  duration,
bool *  expired = nullptr 
)

Continuously make a given process wait for given processes to finish or events to be set.

Parameters
nCountNumber of IDs being passed.
pidListList of process IDs to wait for.
bWaitAllWhether to wait for all or any of the processes/events.
durationDuration in milliseconds.
expiredSet to true if the delay period expired.

◆ sleep()

void Common::CoroutineScheduler::sleep ( Common::CoroContext coroParam,
uint32  duration 
)

Make the active process sleep for the given duration in milliseconds.

Parameters
durationDuration in milliseconds
Remarks
This duration is not precise, since it relies on the frequency the scheduler is called.

◆ createProcess() [1/3]

PROCESS* Common::CoroutineScheduler::createProcess ( uint32  pid,
CORO_ADDR  coroAddr,
const void *  pParam,
int  sizeParam 
)

Create a new process.

Parameters
pidProcess identifier.
coroAddrCoroutine start address.
pParamProcess-specific information.
sizeParamSize of the process-specific information.

◆ createProcess() [2/3]

uint32 Common::CoroutineScheduler::createProcess ( CORO_ADDR  coroAddr,
const void *  pParam,
int  sizeParam 
)

Create a new process with an auto-incrementing Process ID.

Parameters
coroAddrCoroutine start address.
pParamProcess-specific information.
sizeParamSize of process-specific information.

◆ createProcess() [3/3]

uint32 Common::CoroutineScheduler::createProcess ( CORO_ADDR  coroAddr,
const void *  pParam 
)

Create a new process with an auto-incrementing Process ID and a single pointer parameter.

Parameters
coroAddrCoroutine start address.
pParamProcess-specific information.

◆ killProcess()

void Common::CoroutineScheduler::killProcess ( PROCESS pKillProc)

Kill the specified process.

Parameters
pKillProcThe process to kill.

◆ getCurrentProcess()

PROCESS* Common::CoroutineScheduler::getCurrentProcess ( )

Return a pointer to the currently running process.

◆ getCurrentPID()

int Common::CoroutineScheduler::getCurrentPID ( ) const

Return the process identifier of the currently running process.

◆ killMatchingProcess()

int Common::CoroutineScheduler::killMatchingProcess ( uint32  pidKill,
int  pidMask = -1 
)

Kill any process matching the specified PID. The current process cannot be killed.

Parameters
pidKillProcess identifier of the process to kill.
pidMaskMask to apply to process identifiers before comparison.
Returns
The number of processes killed.

◆ setResourceCallback()

void Common::CoroutineScheduler::setResourceCallback ( VFPTRPP  pFunc)

Set pointer to a function to be called by killProcess().

May be called by a resource allocator. The function supplied is called by killProcess() to allow the resource allocator to free resources allocated to the dying process.

Parameters
pFuncFunction to be called by killProcess().

◆ createEvent()

uint32 Common::CoroutineScheduler::createEvent ( bool  bManualReset,
bool  bInitialState 
)

Create a new event (semaphore) object.

Parameters
bManualResetEvents needs to be manually reset. Otherwise, events will be automatically reset after a process waits for the event to finish.
bInitialStateSpecifies whether the event is signalled or not initially.

◆ closeEvent()

void Common::CoroutineScheduler::closeEvent ( uint32  pidEvent)

Destroy the given event.

Parameters
pidEventEvent Process ID.

◆ setEvent()

void Common::CoroutineScheduler::setEvent ( uint32  pidEvent)

Set the event.

Parameters
pidEventEvent Process ID.

◆ resetEvent()

void Common::CoroutineScheduler::resetEvent ( uint32  pidEvent)

Reset the event.

Parameters
pidEventEvent Process ID.

◆ pulseEvent()

void Common::CoroutineScheduler::pulseEvent ( uint32  pidEvent)

Temporarily set a given event to true, and then run all waiting processes, allowing any processes waiting on the event to be fired. It then immediately resets the event again.

Parameters
pidEventEvent Process ID.
Remarks
Should not be run inside of another process.

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