From 709543dec3eaa07f7d2d7da2157d1f9159bad5d8 Mon Sep 17 00:00:00 2001 From: Pixel Date: Mon, 12 Nov 2001 16:11:04 +0000 Subject: Taskman --- lib/Task.cc | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'lib/Task.cc') 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."); + } +} -- cgit v1.2.3