summaryrefslogtreecommitdiff
path: root/lib/Task.cc
diff options
context:
space:
mode:
authorPixel <Pixel>2001-11-12 16:11:04 +0000
committerPixel <Pixel>2001-11-12 16:11:04 +0000
commit709543dec3eaa07f7d2d7da2157d1f9159bad5d8 (patch)
treed18d30593f7b96ea3d2306bb6784d0a1a1a7a95e /lib/Task.cc
parent6718e4cfec88e3046030f60775293d6de03cdc07 (diff)
Taskman
Diffstat (limited to 'lib/Task.cc')
-rw-r--r--lib/Task.cc27
1 files changed, 26 insertions, 1 deletions
diff --git a/lib/Task.cc b/lib/Task.cc
index faaeaf3..42147d3 100644
--- a/lib/Task.cc
+++ b/lib/Task.cc
@@ -2,7 +2,7 @@
#include "Task.h"
#include "String.h"
-Task::Task() : state(TASK_ON_HOLD) {}
+Task::Task() : state(TASK_ON_HOLD), suspended(false) {}
Task::~Task() {}
int Task::Do() {
@@ -15,6 +15,7 @@ int Task::Run() {
state = Do();
}
catch (TaskSwitch) {
+ Resume(1);
throw;
}
catch (GeneralException e) {
@@ -32,3 +33,27 @@ int Task::GetState() {
String Task::GetName() {
return "Unknow Task";
}
+
+int Task::Suspend() throw (GeneralException) {
+ int r;
+
+ cerr << "Suspending task " << GetName() << "...\n";
+
+ suspended = true;
+
+ r = setjmp(env);
+
+ if (!r) throw TaskSwitch();
+
+ return r;
+}
+
+void Task::Resume(int val) throw (GeneralException) {
+ if (suspended) {
+ cerr << "Resuming task " << GetName() << "...\n";
+ suspended = false;
+ longjmp(env, val);
+ } else {
+ throw GeneralException(String("Task ") + GetName() + " was not suspended.");
+ }
+}