summaryrefslogtreecommitdiff
path: root/lib/Task.cc
diff options
context:
space:
mode:
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.");
+ }
+}