ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

Creates and manages "processes" (really coroutines). More...

#include <coroutines.h>

Inheritance diagram for Common::CoroutineScheduler:
Collaboration diagram for Common::CoroutineScheduler:

List of all members.

Public Types

typedef void(* VFPTRPP )(PROCESS *)
 Pointer to a function of the form "void function(PPROCESS)".

Public Member Functions

void reset ()
 Kills all processes and places them on the free list.
void schedule ()
 Give all active processes a chance to run.
void rescheduleAll ()
 Reschedules all the processes to run again this tick.
void reschedule (PPROCESS pReSchedProc=nullptr)
 If the specified process has already run on this tick, make it run again on the current tick.
void giveWay (PPROCESS pReSchedProc=nullptr)
 Moves the specified process to the end of the dispatch queue allowing it to run again within the current game cycle.
void waitForSingleObject (CORO_PARAM, int pid, uint32 duration, bool *expired=nullptr)
 Continously makes a given process wait for another process to finish or event to signal.
void waitForMultipleObjects (CORO_PARAM, int nCount, uint32 *pidList, bool bWaitAll, uint32 duration, bool *expired=nullptr)
 Continously makes a given process wait for given prcesses to finished or events to be set.
void sleep (CORO_PARAM, uint32 duration)
 Make the active process sleep for the given duration in milliseconds.
PROCESScreateProcess (uint32 pid, CORO_ADDR coroAddr, const void *pParam, int sizeParam)
 Creates a new process.
uint32 createProcess (CORO_ADDR coroAddr, const void *pParam, int sizeParam)
 Creates a new process with an auto-incrementing Process Id.
uint32 createProcess (CORO_ADDR coroAddr, const void *pParam)
 Creates a new process with an auto-incrementing Process Id, and a single pointer parameter.
void killProcess (PROCESS *pKillProc)
 Kills the specified process.
PROCESSgetCurrentProcess ()
 Returns a pointer to the currently running process.
int getCurrentPID () const
 Returns the process identifier of the currently running process.
int killMatchingProcess (uint32 pidKill, int pidMask=-1)
 Kills any process matching the specified PID.
void setResourceCallback (VFPTRPP pFunc)
 Set pointer to a function to be called by killProcess().
uint32 createEvent (bool bManualReset, bool bInitialState)
 Creates a new event (semaphore) object.
void closeEvent (uint32 pidEvent)
 Destroys the given event.
void setEvent (uint32 pidEvent)
 Sets the event.
void resetEvent (uint32 pidEvent)
 Resets the event.
void pulseEvent (uint32 pidEvent)
 Temporarily sets a given event to true, and then runs all waiting processes,allowing any processes waiting on the event to be fired.

Private Member Functions

 CoroutineScheduler ()
 Constructor.
 ~CoroutineScheduler ()
 Destructor.
PROCESSgetProcess (uint32 pid)
EVENTgetEvent (uint32 pid)

Private Attributes

PROCESSprocessList
 list of all processes
PROCESSactive
 active process list - also saves scheduler state
PROCESSpFreeProcesses
 pointer to free process list
PROCESSpCurrent
 the currently active process
int pidCounter
 Auto-incrementing process Id.
Common::List< EVENT * > _events
 Event list.
VFPTRPP pRCfunction
 Called from killProcess() to enable other resources a process may be allocated to be released.

Friends

class Singleton< CoroutineScheduler >

Detailed Description

Creates and manages "processes" (really coroutines).

Definition at line 328 of file coroutines.h.


Member Typedef Documentation

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

Definition at line 331 of file coroutines.h.


Constructor & Destructor Documentation

Common::CoroutineScheduler::CoroutineScheduler (  )  [private]

Constructor.

Definition at line 97 of file coroutines.cpp.

Common::CoroutineScheduler::~CoroutineScheduler (  )  [private]

Destructor.

Definition at line 118 of file coroutines.cpp.


Member Function Documentation

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

Destroys the given event.

Parameters:
pidEvent Event Process Id

Definition at line 697 of file coroutines.cpp.

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

Creates a new event (semaphore) object.

Parameters:
bManualReset Events needs to be manually reset. Otherwise, events will be automatically reset after a process waits on the event finishes
bInitialState Specifies whether the event is signalled or not initially

Definition at line 686 of file coroutines.cpp.

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

Creates a new process.

Parameters:
pid process identifier
coroAddr Coroutine start address
pParam Process specific info
sizeParam Size of process specific info

Definition at line 491 of file coroutines.cpp.

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

Creates a new process with an auto-incrementing Process Id.

Parameters:
coroAddr Coroutine start address
pParam Process specific info
sizeParam Size of process specific info

Definition at line 555 of file coroutines.cpp.

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

Creates a new process with an auto-incrementing Process Id, and a single pointer parameter.

Parameters:
coroAddr Coroutine start address
pParam Process specific info

Definition at line 560 of file coroutines.cpp.

int Common::CoroutineScheduler::getCurrentPID (  )  const

Returns the process identifier of the currently running process.

Definition at line 603 of file coroutines.cpp.

PROCESS * Common::CoroutineScheduler::getCurrentProcess (  ) 

Returns a pointer to the currently running process.

Definition at line 599 of file coroutines.cpp.

EVENT * Common::CoroutineScheduler::getEvent ( uint32  pid  )  [private]

Definition at line 674 of file coroutines.cpp.

PROCESS * Common::CoroutineScheduler::getProcess ( uint32  pid  )  [private]

Definition at line 666 of file coroutines.cpp.

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

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

Parameters:
pGiveProc Which process

Definition at line 312 of file coroutines.cpp.

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

Kills any process matching the specified PID.

The current process cannot be killed.

Parameters:
pidKill Process identifier of process to kill
pidMask Mask to apply to process identifiers before comparison
Returns:
The number of processes killed is returned.

Definition at line 613 of file coroutines.cpp.

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

Kills the specified process.

Parameters:
pKillProc Which process to kill

Definition at line 564 of file coroutines.cpp.

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

Temporarily sets a given event to true, and then runs all waiting processes,allowing any processes waiting on the event to be fired.

It then immediately resets the event again.

Parameters:
pidEvent Event Process Id
Remarks:
Should not be run inside of another process

Definition at line 717 of file coroutines.cpp.

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.

Definition at line 275 of file coroutines.cpp.

void Common::CoroutineScheduler::rescheduleAll (  ) 

Reschedules all the processes to run again this tick.

Definition at line 260 of file coroutines.cpp.

void Common::CoroutineScheduler::reset (  ) 

Kills all processes and places them on the free list.

Definition at line 139 of file coroutines.cpp.

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

Resets the event.

Parameters:
pidEvent Event Process Id

Definition at line 711 of file coroutines.cpp.

void Common::CoroutineScheduler::schedule (  ) 

Give all active processes a chance to run.

Definition at line 222 of file coroutines.cpp.

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

Sets the event.

Parameters:
pidEvent Event Process Id

Definition at line 705 of file coroutines.cpp.

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:
pFunc Function to be called by killProcess()

Definition at line 662 of file coroutines.cpp.

void Common::CoroutineScheduler::sleep ( CORO_PARAM  ,
uint32  duration 
)

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

Parameters:
duration Duration in milliseconds
Remarks:
This duration won't be precise, since it relies on the frequency the scheduler is called.

Definition at line 468 of file coroutines.cpp.

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

Continously makes a given process wait for given prcesses to finished or events to be set.

Parameters:
nCount Number of Id's being passed
evtList List of pids to wait for
bWaitAll Specifies whether all or any of the processes/events
duration Duration in milliseconds
expired Set to true if delay period expired

Definition at line 401 of file coroutines.cpp.

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

Continously makes a given process wait for another process to finish or event to signal.

Parameters:
pid Process/Event identifier
duration Duration in milliseconds
expired If specified, set to true if delay period expired

Definition at line 345 of file coroutines.cpp.


Friends And Related Function Documentation

friend class Singleton< CoroutineScheduler > [friend]

Definition at line 334 of file coroutines.h.


Member Data Documentation

Event list.

Definition at line 363 of file coroutines.h.

active process list - also saves scheduler state

Definition at line 351 of file coroutines.h.

the currently active process

Definition at line 357 of file coroutines.h.

pointer to free process list

Definition at line 354 of file coroutines.h.

Auto-incrementing process Id.

Definition at line 360 of file coroutines.h.

Called from killProcess() to enable other resources a process may be allocated to be released.

Definition at line 381 of file coroutines.h.

list of all processes

Definition at line 348 of file coroutines.h.


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


Generated on Sat Mar 23 2019 05:06:55 for ResidualVM by doxygen 1.7.1
curved edge   curved edge