aboutsummaryrefslogtreecommitdiff
path: root/engines/tony/sched.cpp
diff options
context:
space:
mode:
authorPaul Gilbert2012-05-09 00:42:27 +1000
committerPaul Gilbert2012-05-09 00:42:27 +1000
commit26898dd7ad399a641f63eabf04aa2d839f8508fc (patch)
tree7662cd1fc594e4d1c3ef2750c215a552a1c98bf7 /engines/tony/sched.cpp
parenta254f100253bda1b23f280226b7b4d909206d49c (diff)
downloadscummvm-rg350-26898dd7ad399a641f63eabf04aa2d839f8508fc.tar.gz
scummvm-rg350-26898dd7ad399a641f63eabf04aa2d839f8508fc.tar.bz2
scummvm-rg350-26898dd7ad399a641f63eabf04aa2d839f8508fc.zip
TONY: Completed bulk of initial coro refactoring
Diffstat (limited to 'engines/tony/sched.cpp')
-rw-r--r--engines/tony/sched.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/engines/tony/sched.cpp b/engines/tony/sched.cpp
index 2671b01b7f..c447afa094 100644
--- a/engines/tony/sched.cpp
+++ b/engines/tony/sched.cpp
@@ -437,6 +437,40 @@ void Scheduler::waitForMultipleObjects(CORO_PARAM, int nCount, uint32 *pidList,
CORO_END_CODE;
}
+/**
+ * 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.
+ */
+void Scheduler::sleep(CORO_PARAM, uint32 duration) {
+ if (!pCurrent)
+ error("Called Scheduler::waitForSingleObject from the main process");
+
+ CORO_BEGIN_CONTEXT;
+ uint32 endTime;
+ PROCESS *pProcess;
+ EVENT *pEvent;
+ CORO_END_CONTEXT(_ctx);
+
+ CORO_BEGIN_CODE(_ctx);
+
+ // Signal as waiting
+ pCurrent->waiting = true;
+
+ _ctx->endTime = g_system->getMillis() + duration;
+
+ // Outer loop for doing checks until expiry
+ while (g_system->getMillis() < _ctx->endTime) {
+ // Sleep until the next cycle
+ CORO_SLEEP(1);
+ }
+
+ // Signal waiting is done
+ pCurrent->waiting = false;
+
+ CORO_END_CODE;
+}
/**
* Creates a new process.