aboutsummaryrefslogtreecommitdiff
path: root/common/coroutines.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/coroutines.cpp')
-rw-r--r--common/coroutines.cpp88
1 files changed, 44 insertions, 44 deletions
diff --git a/common/coroutines.cpp b/common/coroutines.cpp
index 248777febd..0e7a1098cf 100644
--- a/common/coroutines.cpp
+++ b/common/coroutines.cpp
@@ -31,7 +31,7 @@
namespace Common {
/** Helper null context instance */
-CoroContext nullContext = NULL;
+CoroContext nullContext = nullptr;
DECLARE_SINGLETON(CoroutineScheduler);
@@ -73,7 +73,7 @@ static void displayCoroStats() {
#endif
CoroBaseContext::CoroBaseContext(const char *func)
- : _line(0), _sleep(0), _subctx(0) {
+ : _line(0), _sleep(0), _subctx(nullptr) {
#ifdef COROUTINE_DEBUG
_funcName = func;
changeCoroStats(_funcName, +1);
@@ -95,9 +95,9 @@ CoroBaseContext::~CoroBaseContext() {
//--------------------- Scheduler Class ------------------------
CoroutineScheduler::CoroutineScheduler() {
- processList = NULL;
- pFreeProcesses = NULL;
- pCurrent = NULL;
+ processList = nullptr;
+ pFreeProcesses = nullptr;
+ pCurrent = nullptr;
#ifdef DEBUG
// diagnostic process counters
@@ -105,12 +105,12 @@ CoroutineScheduler::CoroutineScheduler() {
maxProcs = 0;
#endif
- pRCfunction = NULL;
+ pRCfunction = nullptr;
pidCounter = 0;
active = new PROCESS;
- active->pPrevious = NULL;
- active->pNext = NULL;
+ active->pPrevious = nullptr;
+ active->pNext = nullptr;
reset();
}
@@ -118,17 +118,17 @@ CoroutineScheduler::CoroutineScheduler() {
CoroutineScheduler::~CoroutineScheduler() {
// Kill all running processes (i.e. free memory allocated for their state).
PROCESS *pProc = active->pNext;
- while (pProc != NULL) {
+ while (pProc != nullptr) {
delete pProc->state;
- pProc->state = 0;
+ pProc->state = nullptr;
pProc = pProc->pNext;
}
free(processList);
- processList = NULL;
+ processList = nullptr;
delete active;
- active = 0;
+ active = nullptr;
// Clear the event list
Common::List<EVENT *>::iterator i;
@@ -142,12 +142,12 @@ void CoroutineScheduler::reset() {
numProcs = 0;
#endif
- if (processList == NULL) {
+ if (processList == nullptr) {
// first time - allocate memory for process list
processList = (PROCESS *)calloc(CORO_MAX_PROCESSES, sizeof(PROCESS));
// make sure memory allocated
- if (processList == NULL) {
+ if (processList == nullptr) {
error("Cannot allocate memory for process data");
}
@@ -157,22 +157,22 @@ void CoroutineScheduler::reset() {
// Kill all running processes (i.e. free memory allocated for their state).
PROCESS *pProc = active->pNext;
- while (pProc != NULL) {
+ while (pProc != nullptr) {
delete pProc->state;
- pProc->state = 0;
+ pProc->state = nullptr;
Common::fill(&pProc->pidWaiting[0], &pProc->pidWaiting[CORO_MAX_PID_WAITING], 0);
pProc = pProc->pNext;
}
// no active processes
- pCurrent = active->pNext = NULL;
+ pCurrent = active->pNext = nullptr;
// place first process on free list
pFreeProcesses = processList;
// link all other processes after first
for (int i = 1; i <= CORO_NUM_PROCESS; i++) {
- processList[i - 1].pNext = (i == CORO_NUM_PROCESS) ? NULL : processList + i;
+ processList[i - 1].pNext = (i == CORO_NUM_PROCESS) ? nullptr : processList + i;
processList[i - 1].pPrevious = (i == 1) ? active : processList + (i - 2);
}
}
@@ -223,7 +223,7 @@ void CoroutineScheduler::schedule() {
// start dispatching active process list
PROCESS *pNext;
PROCESS *pProc = active->pNext;
- while (pProc != NULL) {
+ while (pProc != nullptr) {
pNext = pProc->pNext;
if (--pProc->sleepTime <= 0) {
@@ -241,7 +241,7 @@ void CoroutineScheduler::schedule() {
// pCurrent may have been changed
pNext = pCurrent->pNext;
- pCurrent = NULL;
+ pCurrent = nullptr;
}
pProc = pNext;
@@ -284,16 +284,16 @@ void CoroutineScheduler::reschedule(PPROCESS pReSchedProc) {
// Find the last process in the list.
// But if the target process is down the list from here, do nothing
- for (pEnd = pCurrent; pEnd->pNext != NULL; pEnd = pEnd->pNext) {
+ for (pEnd = pCurrent; pEnd->pNext != nullptr; pEnd = pEnd->pNext) {
if (pEnd->pNext == pReSchedProc)
return;
}
- assert(pEnd->pNext == NULL);
+ assert(pEnd->pNext == nullptr);
// Could be in the middle of a KillProc()!
// Dying process was last and this process was penultimate
- if (pReSchedProc->pNext == NULL)
+ if (pReSchedProc->pNext == nullptr)
return;
// If we're moving the current process, move it back by one, so that the next
@@ -306,7 +306,7 @@ void CoroutineScheduler::reschedule(PPROCESS pReSchedProc) {
pReSchedProc->pNext->pPrevious = pReSchedProc->pPrevious;
pEnd->pNext = pReSchedProc;
pReSchedProc->pPrevious = pEnd;
- pReSchedProc->pNext = NULL;
+ pReSchedProc->pNext = nullptr;
}
void CoroutineScheduler::giveWay(PPROCESS pReSchedProc) {
@@ -324,9 +324,9 @@ void CoroutineScheduler::giveWay(PPROCESS pReSchedProc) {
PPROCESS pEnd;
// Find the last process in the list.
- for (pEnd = pCurrent; pEnd->pNext != NULL; pEnd = pEnd->pNext)
+ for (pEnd = pCurrent; pEnd->pNext != nullptr; pEnd = pEnd->pNext)
;
- assert(pEnd->pNext == NULL);
+ assert(pEnd->pNext == nullptr);
// If we're moving the current process, move it back by one, so that the next
@@ -339,7 +339,7 @@ void CoroutineScheduler::giveWay(PPROCESS pReSchedProc) {
pReSchedProc->pNext->pPrevious = pReSchedProc->pPrevious;
pEnd->pNext = pReSchedProc;
pReSchedProc->pPrevious = pEnd;
- pReSchedProc->pNext = NULL;
+ pReSchedProc->pNext = nullptr;
}
void CoroutineScheduler::waitForSingleObject(CORO_PARAM, int pid, uint32 duration, bool *expired) {
@@ -366,11 +366,11 @@ void CoroutineScheduler::waitForSingleObject(CORO_PARAM, int pid, uint32 duratio
while (g_system->getMillis() <= _ctx->endTime) {
// Check to see if a process or event with the given Id exists
_ctx->pProcess = getProcess(pid);
- _ctx->pEvent = !_ctx->pProcess ? getEvent(pid) : NULL;
+ _ctx->pEvent = !_ctx->pProcess ? getEvent(pid) : nullptr;
// If there's no active process or event, presume it's a process that's finished,
// so the waiting can immediately exit
- if ((_ctx->pProcess == NULL) && (_ctx->pEvent == NULL)) {
+ if ((_ctx->pProcess == nullptr) && (_ctx->pEvent == nullptr)) {
if (expired)
*expired = false;
break;
@@ -378,7 +378,7 @@ void CoroutineScheduler::waitForSingleObject(CORO_PARAM, int pid, uint32 duratio
// If a process was found, don't go into the if statement, and keep waiting.
// Likewise if it's an event that's not yet signalled
- if ((_ctx->pEvent != NULL) && _ctx->pEvent->signalled) {
+ if ((_ctx->pEvent != nullptr) && _ctx->pEvent->signalled) {
// Unless the event is flagged for manual reset, reset it now
if (!_ctx->pEvent->manualReset)
_ctx->pEvent->signalled = false;
@@ -429,7 +429,7 @@ void CoroutineScheduler::waitForMultipleObjects(CORO_PARAM, int nCount, uint32 *
for (_ctx->i = 0; _ctx->i < nCount; ++_ctx->i) {
_ctx->pProcess = getProcess(pidList[_ctx->i]);
- _ctx->pEvent = !_ctx->pProcess ? getEvent(pidList[_ctx->i]) : NULL;
+ _ctx->pEvent = !_ctx->pProcess ? getEvent(pidList[_ctx->i]) : nullptr;
// Determine the signalled state
_ctx->pidSignalled = (_ctx->pProcess) || !_ctx->pEvent ? false : _ctx->pEvent->signalled;
@@ -495,7 +495,7 @@ PROCESS *CoroutineScheduler::createProcess(uint32 pid, CORO_ADDR coroAddr, const
pProc = pFreeProcesses;
// trap no free process
- assert(pProc != NULL); // Out of processes
+ assert(pProc != nullptr); // Out of processes
#ifdef DEBUG
// one more process in use
@@ -506,9 +506,9 @@ PROCESS *CoroutineScheduler::createProcess(uint32 pid, CORO_ADDR coroAddr, const
// get link to next free process
pFreeProcesses = pProc->pNext;
if (pFreeProcesses)
- pFreeProcesses->pPrevious = NULL;
+ pFreeProcesses->pPrevious = nullptr;
- if (pCurrent != NULL) {
+ if (pCurrent != nullptr) {
// place new process before the next active process
pProc->pNext = pCurrent->pNext;
if (pProc->pNext)
@@ -532,7 +532,7 @@ PROCESS *CoroutineScheduler::createProcess(uint32 pid, CORO_ADDR coroAddr, const
pProc->coroAddr = coroAddr;
// clear coroutine state
- pProc->state = 0;
+ pProc->state = nullptr;
// wake process up as soon as possible
pProc->sleepTime = 1;
@@ -575,11 +575,11 @@ void CoroutineScheduler::killProcess(PROCESS *pKillProc) {
#endif
// Free process' resources
- if (pRCfunction != NULL)
+ if (pRCfunction != nullptr)
(pRCfunction)(pKillProc);
delete pKillProc->state;
- pKillProc->state = 0;
+ pKillProc->state = nullptr;
// Take the process out of the active chain list
pKillProc->pPrevious->pNext = pKillProc->pNext;
@@ -590,7 +590,7 @@ void CoroutineScheduler::killProcess(PROCESS *pKillProc) {
pKillProc->pNext = pFreeProcesses;
if (pFreeProcesses)
pKillProc->pNext->pPrevious = pKillProc;
- pKillProc->pPrevious = NULL;
+ pKillProc->pPrevious = nullptr;
// make pKillProc the first free process
pFreeProcesses = pKillProc;
@@ -614,7 +614,7 @@ int CoroutineScheduler::killMatchingProcess(uint32 pidKill, int pidMask) {
int numKilled = 0;
PROCESS *pProc, *pPrev; // process list pointers
- for (pProc = active->pNext, pPrev = active; pProc != NULL; pPrev = pProc, pProc = pProc->pNext) {
+ for (pProc = active->pNext, pPrev = active; pProc != nullptr; pPrev = pProc, pProc = pProc->pNext) {
if ((pProc->pid & (uint32)pidMask) == pidKill) {
// found a matching process
@@ -624,11 +624,11 @@ int CoroutineScheduler::killMatchingProcess(uint32 pidKill, int pidMask) {
numKilled++;
// Free the process' resources
- if (pRCfunction != NULL)
+ if (pRCfunction != nullptr)
(pRCfunction)(pProc);
delete pProc->state;
- pProc->state = 0;
+ pProc->state = nullptr;
// make prev point to next to unlink pProc
pPrev->pNext = pProc->pNext;
@@ -637,7 +637,7 @@ int CoroutineScheduler::killMatchingProcess(uint32 pidKill, int pidMask) {
// link first free process after pProc
pProc->pNext = pFreeProcesses;
- pProc->pPrevious = NULL;
+ pProc->pPrevious = nullptr;
pFreeProcesses->pPrevious = pProc;
// make pProc the first free process
@@ -665,7 +665,7 @@ void CoroutineScheduler::setResourceCallback(VFPTRPP pFunc) {
PROCESS *CoroutineScheduler::getProcess(uint32 pid) {
PROCESS *pProc = active->pNext;
- while ((pProc != NULL) && (pProc->pid != pid))
+ while ((pProc != nullptr) && (pProc->pid != pid))
pProc = pProc->pNext;
return pProc;
@@ -679,7 +679,7 @@ EVENT *CoroutineScheduler::getEvent(uint32 pid) {
return evt;
}
- return NULL;
+ return nullptr;
}