DOXYGEN: doxygen changes in header files 2
Edited files in the common folder: - bufferedstream.h - callback.h - config-manager.h - coroutines.h - cosinetables.h - dcl.h - debug.h - debug-channels.h
This commit is contained in:
parent
b6c5d415ee
commit
c52f7e0e04
9 changed files with 265 additions and 238 deletions
|
@ -60,12 +60,12 @@ struct CoroBaseContext {
|
|||
const char *_funcName;
|
||||
#endif
|
||||
/**
|
||||
* Creates a coroutine context
|
||||
* Create a coroutine context.
|
||||
*/
|
||||
CoroBaseContext(const char *func);
|
||||
|
||||
/**
|
||||
* Destructor for coroutine context
|
||||
* Destructor for coroutine context.
|
||||
*/
|
||||
virtual ~CoroBaseContext();
|
||||
};
|
||||
|
@ -74,7 +74,7 @@ typedef CoroBaseContext *CoroContext;
|
|||
|
||||
|
||||
/** This is a special constant that can be temporarily used as a parameter to call coroutine-ised
|
||||
* methods from code that haven't yet been converted to being a coroutine, so code at least
|
||||
* methods from code that have not yet been converted to being a coroutine, so code at least
|
||||
* compiles correctly. Be aware, though, that an error will occur if a coroutine that was passed
|
||||
* the nullContext tries to sleep or yield control.
|
||||
*/
|
||||
|
@ -82,9 +82,9 @@ extern CoroContext nullContext;
|
|||
|
||||
/**
|
||||
* Wrapper class which holds a pointer to a pointer to a CoroBaseContext.
|
||||
* The interesting part is the destructor, which kills the context being held,
|
||||
* Note that the destructor kills the context being held,
|
||||
* but ONLY if the _sleep val of that context is zero. This way, a coroutine
|
||||
* can just 'return' w/o having to worry about freeing the allocated context
|
||||
* can just 'return' without freeing the allocated context
|
||||
* (in Simon Tatham's original code, one had to use a special macro to
|
||||
* return from a coroutine).
|
||||
*/
|
||||
|
@ -104,30 +104,30 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
/** Methods that have been converted to being a coroutine should have this as the first parameter */
|
||||
/** Set this as the first parameter for methods that have been converted to being a coroutine. */
|
||||
#define CORO_PARAM Common::CoroContext &coroParam
|
||||
|
||||
|
||||
/**
|
||||
* Begin the declaration of a coroutine context.
|
||||
* This allows declaring variables which are 'persistent' during the
|
||||
* lifetime of the coroutine. An example use would be:
|
||||
*
|
||||
* lifetime of the coroutine. Example usage:
|
||||
* @code
|
||||
* CORO_BEGIN_CONTEXT;
|
||||
* int var;
|
||||
* char *foo;
|
||||
* CORO_END_CONTEXT(_ctx);
|
||||
*
|
||||
* @endcode
|
||||
* It is not possible to initialize variables here, due to the way this
|
||||
* macro is implemented. Furthermore, to use the variables declared in
|
||||
* the coroutine context, you have to access them via the context variable
|
||||
* name that was specified as parameter to CORO_END_CONTEXT, e.g.
|
||||
* the coroutine context, you must access them through the context variable
|
||||
* name that was specified as a parameter to @c CORO_END_CONTEXT, e.g.
|
||||
* _ctx->var = 0;
|
||||
*
|
||||
* @see CORO_END_CONTEXT
|
||||
*
|
||||
* @note We declare a variable 'DUMMY' to allow the user to specify an 'empty'
|
||||
* context, and so compilers won't complain about ";" following the macro.
|
||||
* @note A 'DUMMY' variable is declared to allow the user to specify an 'empty'
|
||||
* context, and so that compilers do not complain about ";" following the macro.
|
||||
*/
|
||||
#define CORO_BEGIN_CONTEXT \
|
||||
struct CoroContextTag : Common::CoroBaseContext { \
|
||||
|
@ -136,15 +136,14 @@ public:
|
|||
|
||||
/**
|
||||
* End the declaration of a coroutine context.
|
||||
* @param x name of the coroutine context
|
||||
* @param x Name of the coroutine context.
|
||||
* @see CORO_BEGIN_CONTEXT
|
||||
*/
|
||||
#define CORO_END_CONTEXT(x) } *x = (CoroContextTag *)coroParam
|
||||
|
||||
/**
|
||||
* Begin the code section of a coroutine.
|
||||
* @param x name of the coroutine context
|
||||
* @see CORO_BEGIN_CODE
|
||||
* @param x Name of the coroutine context.
|
||||
*/
|
||||
#define CORO_BEGIN_CODE(x) \
|
||||
if (&coroParam == &Common::nullContext) assert(!Common::nullContext); \
|
||||
|
@ -155,7 +154,6 @@ public:
|
|||
|
||||
/**
|
||||
* End the code section of a coroutine.
|
||||
* @see CORO_END_CODE
|
||||
*/
|
||||
#define CORO_END_CODE \
|
||||
if (&coroParam == &Common::nullContext) { \
|
||||
|
@ -181,9 +179,9 @@ public:
|
|||
/**
|
||||
* Stop the currently running coroutine and all calling coroutines.
|
||||
*
|
||||
* This sets _sleep to -1 rather than 0 so that the context doesn't get
|
||||
* deleted by CoroContextHolder, since we want CORO_INVOKE_ARGS to
|
||||
* propogate the _sleep value and return immediately (the scheduler will
|
||||
* This sets _sleep to -1 rather than 0 so that the context does not get
|
||||
* deleted by CoroContextHolder, since we want @ref CORO_INVOKE_ARGS to
|
||||
* propagate the _sleep value and return immediately (the scheduler will
|
||||
* then delete the entire coroutine's state, including all subcontexts).
|
||||
*/
|
||||
#define CORO_KILL_SELF() \
|
||||
|
@ -191,8 +189,8 @@ public:
|
|||
|
||||
|
||||
/**
|
||||
* This macro is to be used in conjunction with CORO_INVOKE_ARGS and
|
||||
* similar macros for calling coroutines-enabled subroutines.
|
||||
* Use this macro in conjunction with @ref CORO_INVOKE_ARGS and
|
||||
* similar macros for calling coroutine-enabled subroutines.
|
||||
*/
|
||||
#define CORO_SUBCTX coroParam->_subctx
|
||||
|
||||
|
@ -206,10 +204,10 @@ public:
|
|||
* If the subcontext is null, the coroutine ended normally, and we can
|
||||
* simply break out of the loop and continue execution.
|
||||
*
|
||||
* @param subCoro name of the coroutine-enabled function to invoke
|
||||
* @param ARGS list of arguments to pass to subCoro
|
||||
* @param subCoro Name of the coroutine-enabled function to invoke.
|
||||
* @param ARGS List of arguments to pass to subCoro.
|
||||
*
|
||||
* @note ARGS must be surrounded by parentheses, and the first argument
|
||||
* @note @p ARGS must be surrounded by parentheses, and the first argument
|
||||
* in this list must always be CORO_SUBCTX. For example, the
|
||||
* regular function call
|
||||
* myFunc(a, b);
|
||||
|
@ -230,9 +228,9 @@ public:
|
|||
} while (0)
|
||||
|
||||
/**
|
||||
* Invoke another coroutine. Similar to CORO_INVOKE_ARGS,
|
||||
* Invoke another coroutine. Similar to @ref CORO_INVOKE_ARGS,
|
||||
* but allows specifying a return value which is returned
|
||||
* if invoked coroutine yields (thus causing the current
|
||||
* if the invoked coroutine yields (thus causing the current
|
||||
* coroutine to yield, too).
|
||||
*/
|
||||
#define CORO_INVOKE_ARGS_V(subCoro, RESULT, ARGS) \
|
||||
|
@ -249,14 +247,14 @@ public:
|
|||
} while (0)
|
||||
|
||||
/**
|
||||
* Convenience wrapper for CORO_INVOKE_ARGS for invoking a coroutine
|
||||
* Convenience wrapper for @ref CORO_INVOKE_ARGS for invoking a coroutine
|
||||
* with no parameters.
|
||||
*/
|
||||
#define CORO_INVOKE_0(subCoroutine) \
|
||||
CORO_INVOKE_ARGS(subCoroutine, (CORO_SUBCTX))
|
||||
|
||||
/**
|
||||
* Convenience wrapper for CORO_INVOKE_ARGS for invoking a coroutine
|
||||
* Convenience wrapper for @ref CORO_INVOKE_ARGS for invoking a coroutine
|
||||
* with one parameter.
|
||||
*/
|
||||
#define CORO_INVOKE_1(subCoroutine, a0) \
|
||||
|
@ -270,7 +268,7 @@ public:
|
|||
CORO_INVOKE_ARGS(subCoroutine, (CORO_SUBCTX, a0, a1))
|
||||
|
||||
/**
|
||||
* Convenience wrapper for CORO_INVOKE_ARGS for invoking a coroutine
|
||||
* Convenience wrapper for @ref CORO_INVOKE_ARGS for invoking a coroutine
|
||||
* with three parameters.
|
||||
*/
|
||||
#define CORO_INVOKE_3(subCoroutine, a0,a1,a2) \
|
||||
|
@ -285,10 +283,10 @@ public:
|
|||
|
||||
|
||||
|
||||
// the size of process specific info
|
||||
/** Size of process-specific information. */
|
||||
#define CORO_PARAM_SIZE 32
|
||||
|
||||
// the maximum number of processes
|
||||
/** Maximum number of processes. */
|
||||
#define CORO_NUM_PROCESS 100
|
||||
#define CORO_MAX_PROCESSES 100
|
||||
#define CORO_MAX_PID_WAITING 5
|
||||
|
@ -296,26 +294,26 @@ public:
|
|||
#define CORO_INFINITE 0xffffffff
|
||||
#define CORO_INVALID_PID_VALUE 0
|
||||
|
||||
/** Coroutine parameter for methods converted to coroutines */
|
||||
/** Coroutine parameter for methods converted to coroutines. */
|
||||
typedef void (*CORO_ADDR)(CoroContext &, const void *);
|
||||
|
||||
/** process structure */
|
||||
struct PROCESS {
|
||||
PROCESS *pNext; ///< pointer to next process in active or free list
|
||||
PROCESS *pPrevious; ///< pointer to previous process in active or free list
|
||||
PROCESS *pNext; ///< Pointer to the next process in an active or free list.
|
||||
PROCESS *pPrevious; ///< Pointer to the previous process in an active or free list.
|
||||
|
||||
CoroContext state; ///< the state of the coroutine
|
||||
CORO_ADDR coroAddr; ///< the entry point of the coroutine
|
||||
CoroContext state; ///< State of the coroutine.
|
||||
CORO_ADDR coroAddr; ///< Entry point of the coroutine.
|
||||
|
||||
int sleepTime; ///< number of scheduler cycles to sleep
|
||||
uint32 pid; ///< process ID
|
||||
uint32 pidWaiting[CORO_MAX_PID_WAITING]; ///< Process ID(s) process is currently waiting on
|
||||
char param[CORO_PARAM_SIZE]; ///< process specific info
|
||||
int sleepTime; ///< Number of scheduler cycles to sleep.
|
||||
uint32 pid; ///< Process ID.
|
||||
uint32 pidWaiting[CORO_MAX_PID_WAITING]; ///< Process ID(s) that the process is currently waiting on.
|
||||
char param[CORO_PARAM_SIZE]; ///< Process-specific information.
|
||||
};
|
||||
typedef PROCESS *PPROCESS;
|
||||
|
||||
|
||||
/** Event structure */
|
||||
/** Event structure. */
|
||||
struct EVENT {
|
||||
uint32 pid;
|
||||
bool manualReset;
|
||||
|
@ -325,7 +323,7 @@ struct EVENT {
|
|||
|
||||
|
||||
/**
|
||||
* Creates and manages "processes" (really coroutines).
|
||||
* Create and manage "processes" (really coroutines).
|
||||
*/
|
||||
class CoroutineScheduler : public Singleton<CoroutineScheduler> {
|
||||
public:
|
||||
|
@ -336,42 +334,42 @@ private:
|
|||
friend class Singleton<CoroutineScheduler>;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Constructor.
|
||||
*/
|
||||
CoroutineScheduler();
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
* Destructor.
|
||||
*/
|
||||
~CoroutineScheduler();
|
||||
|
||||
|
||||
/** list of all processes */
|
||||
/** List of all processes. */
|
||||
PROCESS *processList;
|
||||
|
||||
/** active process list - also saves scheduler state */
|
||||
/** Active process list. Saves scheduler state. */
|
||||
PROCESS *active;
|
||||
|
||||
/** pointer to free process list */
|
||||
/** Pointer to the free process list. */
|
||||
PROCESS *pFreeProcesses;
|
||||
|
||||
/** the currently active process */
|
||||
/** Currently active process. */
|
||||
PROCESS *pCurrent;
|
||||
|
||||
/** Auto-incrementing process Id */
|
||||
/** Auto-incrementing process ID. */
|
||||
int pidCounter;
|
||||
|
||||
/** Event list */
|
||||
/** Event list. */
|
||||
Common::List<EVENT *> _events;
|
||||
|
||||
#ifdef DEBUG
|
||||
// diagnostic process counters
|
||||
/** Diagnostic process counters. */
|
||||
int numProcs;
|
||||
int maxProcs;
|
||||
|
||||
/**
|
||||
* Checks both the active and free process list to insure all the links are valid,
|
||||
* and that no processes have been lost
|
||||
* Check both the active and free process list to ensure that all links are valid,
|
||||
* and that no processes have been lost.
|
||||
*/
|
||||
void checkStack();
|
||||
#endif
|
||||
|
@ -386,24 +384,24 @@ private:
|
|||
EVENT *getEvent(uint32 pid);
|
||||
public:
|
||||
/**
|
||||
* Kills all processes and places them on the free list.
|
||||
* Kill all processes and place them on the free list.
|
||||
*/
|
||||
void reset();
|
||||
|
||||
#ifdef DEBUG
|
||||
/**
|
||||
* Shows the maximum number of process used at once.
|
||||
* Show the maximum number of processes used at once.
|
||||
*/
|
||||
void printStats();
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Give all active processes a chance to run
|
||||
* Give all active processes a chance to run.
|
||||
*/
|
||||
void schedule();
|
||||
|
||||
/**
|
||||
* Reschedules all the processes to run again this tick
|
||||
* Reschedule all processes to run again this tick.
|
||||
*/
|
||||
void rescheduleAll();
|
||||
|
||||
|
@ -414,151 +412,155 @@ public:
|
|||
void reschedule(PPROCESS pReSchedProc = nullptr);
|
||||
|
||||
/**
|
||||
* Moves the specified process to the end of the dispatch queue
|
||||
* Move the specified process to the end of the dispatch queue
|
||||
* allowing it to run again within the current game cycle.
|
||||
* @param pGiveProc Which process
|
||||
* @param pReSchedProc The process to move.
|
||||
*/
|
||||
void giveWay(PPROCESS pReSchedProc = nullptr);
|
||||
|
||||
/**
|
||||
* Continously makes a given process wait for another process to finish or event to signal.
|
||||
* Continously make a given process wait for another process to finish or event to signal.
|
||||
*
|
||||
* @param pid Process/Event identifier
|
||||
* @param duration Duration in milliseconds
|
||||
* @param expired If specified, set to true if delay period expired
|
||||
* @param pid Process/Event identifier.
|
||||
* @param duration Duration in milliseconds.
|
||||
* @param expired If specified, set to true if the delay period expired.
|
||||
*/
|
||||
void waitForSingleObject(CORO_PARAM, int pid, uint32 duration, bool *expired = nullptr);
|
||||
|
||||
/**
|
||||
* Continously makes a given process wait for given prcesses to finished or events to be set
|
||||
* Continously make a given process wait for given processes to finish or events to be set.
|
||||
*
|
||||
* @param nCount Number of Id's being passed
|
||||
* @param evtList List of pids to wait for
|
||||
* @param bWaitAll Specifies whether all or any of the processes/events
|
||||
* @param duration Duration in milliseconds
|
||||
* @param expired Set to true if delay period expired
|
||||
* @param nCount Number of IDs being passed.
|
||||
* @param pidList List of process IDs to wait for.
|
||||
* @param bWaitAll Whether to wait for all or any of the processes/events.
|
||||
* @param duration Duration in milliseconds.
|
||||
* @param expired Set to true if the delay period expired.
|
||||
*/
|
||||
void waitForMultipleObjects(CORO_PARAM, int nCount, uint32 *pidList, bool bWaitAll,
|
||||
uint32 duration, bool *expired = nullptr);
|
||||
|
||||
/**
|
||||
* Make the active process sleep for the given duration in milliseconds
|
||||
* Make the active process sleep for the given duration in milliseconds.
|
||||
*
|
||||
* @param duration Duration in milliseconds
|
||||
* @remarks This duration won't be precise, since it relies on the frequency the
|
||||
* scheduler is called.
|
||||
* @remarks This duration is not precise, since it relies on the frequency the
|
||||
* scheduler is called.
|
||||
*/
|
||||
void sleep(CORO_PARAM, uint32 duration);
|
||||
|
||||
/**
|
||||
* Creates a new process.
|
||||
* Create a new process.
|
||||
*
|
||||
* @param pid process identifier
|
||||
* @param coroAddr Coroutine start address
|
||||
* @param pParam Process specific info
|
||||
* @param sizeParam Size of process specific info
|
||||
* @param pid Process identifier.
|
||||
* @param coroAddr Coroutine start address.
|
||||
* @param pParam Process-specific information.
|
||||
* @param sizeParam Size of the process-specific information.
|
||||
*/
|
||||
PROCESS *createProcess(uint32 pid, CORO_ADDR coroAddr, const void *pParam, int sizeParam);
|
||||
|
||||
/**
|
||||
* Creates a new process with an auto-incrementing Process Id.
|
||||
* Create a new process with an auto-incrementing Process ID.
|
||||
*
|
||||
* @param coroAddr Coroutine start address
|
||||
* @param pParam Process specific info
|
||||
* @param sizeParam Size of process specific info
|
||||
* @param coroAddr Coroutine start address.
|
||||
* @param pParam Process-specific information.
|
||||
* @param sizeParam Size of process-specific information.
|
||||
*/
|
||||
uint32 createProcess(CORO_ADDR coroAddr, const void *pParam, int sizeParam);
|
||||
|
||||
/**
|
||||
* Creates a new process with an auto-incrementing Process Id, and a single pointer parameter.
|
||||
* Create a new process with an auto-incrementing Process ID and a single pointer parameter.
|
||||
*
|
||||
* @param coroAddr Coroutine start address
|
||||
* @param pParam Process specific info
|
||||
* @param coroAddr Coroutine start address.
|
||||
* @param pParam Process-specific information.
|
||||
*/
|
||||
uint32 createProcess(CORO_ADDR coroAddr, const void *pParam);
|
||||
|
||||
/**
|
||||
* Kills the specified process.
|
||||
* Kill the specified process.
|
||||
*
|
||||
* @param pKillProc Which process to kill
|
||||
* @param pKillProc The process to kill.
|
||||
*/
|
||||
void killProcess(PROCESS *pKillProc);
|
||||
|
||||
/**
|
||||
* Returns a pointer to the currently running process.
|
||||
* Return a pointer to the currently running process.
|
||||
*/
|
||||
PROCESS *getCurrentProcess();
|
||||
|
||||
/**
|
||||
* Returns the process identifier of the currently running process.
|
||||
* Return the process identifier of the currently running process.
|
||||
*/
|
||||
int getCurrentPID() const;
|
||||
|
||||
/**
|
||||
* Kills any process matching the specified PID. The current
|
||||
* Kill any process matching the specified PID. The current
|
||||
* process cannot be killed.
|
||||
*
|
||||
* @param pidKill Process identifier of process to kill
|
||||
* @param pidMask Mask to apply to process identifiers before comparison
|
||||
* @return The number of processes killed is returned.
|
||||
* @param pidKill Process identifier of the process to kill.
|
||||
* @param pidMask Mask to apply to process identifiers before comparison.
|
||||
* @return The number of processes killed.
|
||||
*/
|
||||
int killMatchingProcess(uint32 pidKill, int pidMask = -1);
|
||||
|
||||
/**
|
||||
* Set pointer to a function to be called by killProcess().
|
||||
*
|
||||
* May be called by a resource allocator, the function supplied is
|
||||
* 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.
|
||||
*
|
||||
* @param pFunc Function to be called by killProcess()
|
||||
* @param pFunc Function to be called by killProcess().
|
||||
*/
|
||||
void setResourceCallback(VFPTRPP pFunc);
|
||||
|
||||
/* Event methods */
|
||||
/** @name Event methods
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* Creates a new event (semaphore) object
|
||||
* Create a new event (semaphore) object.
|
||||
*
|
||||
* @param bManualReset Events needs to be manually reset. Otherwise,
|
||||
* events will be automatically reset after a
|
||||
* process waits on the event finishes
|
||||
* process waits for the event to finish.
|
||||
* @param bInitialState Specifies whether the event is signalled or not
|
||||
* initially
|
||||
* initially.
|
||||
*/
|
||||
uint32 createEvent(bool bManualReset, bool bInitialState);
|
||||
|
||||
/**
|
||||
* Destroys the given event
|
||||
* @param pidEvent Event Process Id
|
||||
* Destroy the given event.
|
||||
* @param pidEvent Event Process ID.
|
||||
*/
|
||||
void closeEvent(uint32 pidEvent);
|
||||
|
||||
/**
|
||||
* Sets the event
|
||||
* @param pidEvent Event Process Id
|
||||
* Set the event.
|
||||
* @param pidEvent Event Process ID.
|
||||
*/
|
||||
void setEvent(uint32 pidEvent);
|
||||
|
||||
/**
|
||||
* Resets the event
|
||||
* @param pidEvent Event Process Id
|
||||
* Reset the event.
|
||||
* @param pidEvent Event Process ID.
|
||||
*/
|
||||
void resetEvent(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
|
||||
* 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.
|
||||
*
|
||||
* @param pidEvent Event Process Id
|
||||
* @param pidEvent Event Process ID.
|
||||
*
|
||||
* @remarks Should not be run inside of another process
|
||||
* @remarks Should not be run inside of another process.
|
||||
*/
|
||||
void pulseEvent(uint32 pidEvent);
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
/** @} */
|
||||
|
||||
} // end of namespace Common
|
||||
|
||||
#endif // COMMON_COROUTINES_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue