summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/Task.h6
-rw-r--r--lib/LuaTask.cc8
-rw-r--r--lib/Task.cc18
-rw-r--r--lib/TaskMan.cc24
-rw-r--r--lib/tasklib.lua6
5 files changed, 54 insertions, 8 deletions
diff --git a/include/Task.h b/include/Task.h
index 725b2e4..325d162 100644
--- a/include/Task.h
+++ b/include/Task.h
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: Task.h,v 1.31 2007-05-30 11:57:08 pixel Exp $ */
+/* $Id: Task.h,v 1.32 2008-02-18 09:55:08 pixel Exp $ */
#ifndef __TASK_H__
#define __TASK_H__
@@ -64,6 +64,9 @@ class Task : public Base {
void WaitFor(Handle *, int = 0);
void WaitFor(pid_t);
void WaitFor(const timeval &, int = 0);
+ void Yield();
+ bool Yielded();
+ void Unyield();
Task * WaitedBy();
void SetBurst();
void Stop();
@@ -87,6 +90,7 @@ class Task : public Base {
int state;
bool stopped;
bool suspended;
+ bool yielded;
Task * wbta;
Task * wta;
};
diff --git a/lib/LuaTask.cc b/lib/LuaTask.cc
index 7b1e045..095c3e3 100644
--- a/lib/LuaTask.cc
+++ b/lib/LuaTask.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: LuaTask.cc,v 1.27 2008-01-23 17:53:12 pixel Exp $ */
+/* $Id: LuaTask.cc,v 1.28 2008-02-18 09:55:08 pixel Exp $ */
#include <LuaTask.h>
#include <LuaHandle.h>
@@ -143,6 +143,10 @@ int LuaTask::Do() throw (GeneralException) {
}
#endif
+ if (task == "Yield") {
+ nargs = 0;
+ }
+
if (c)
delete c;
c = 0;
@@ -261,6 +265,8 @@ int LuaTask::Do() throw (GeneralException) {
WaitFor(pid);
Suspend(TASK_ON_HOLD);
#endif
+ } else if (task == "Yield") {
+ Yield();
} else {
L->error("Unknow requested task: " + task);
return TASK_DONE;
diff --git a/lib/Task.cc b/lib/Task.cc
index 0b19ab3..6493111 100644
--- a/lib/Task.cc
+++ b/lib/Task.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: Task.cc,v 1.33 2007-05-30 11:57:10 pixel Exp $ */
+/* $Id: Task.cc,v 1.34 2008-02-18 09:55:08 pixel Exp $ */
#ifndef _WIN32
#include <sys/time.h>
@@ -31,7 +31,7 @@
#include "BString.h"
#include "gettext.h"
-Task::Task() : current(0), state(TASK_ON_HOLD), stopped(false), suspended(false), wbta(0), wta(0), BurstHandle(0) {
+Task::Task() : current(0), state(TASK_ON_HOLD), stopped(false), suspended(false), yielded(false), wbta(0), wta(0), BurstHandle(0) {
TaskMan::AddTask(this);
}
@@ -116,6 +116,20 @@ void Task::WaitFor(const timeval & t, int flags) {
TaskMan::WaitFor(t, this, flags);
}
+void Task::Yield() {
+ yielded = true;
+ Suspend(TASK_ON_HOLD);
+}
+
+bool Task::Yielded() {
+ return yielded;
+}
+
+void Task::Unyield() {
+ yielded = false;
+ SetBurst();
+}
+
void Task::SetBurst() {
state = TASK_BURST;
}
diff --git a/lib/TaskMan.cc b/lib/TaskMan.cc
index 4cc7fd2..ee7958b 100644
--- a/lib/TaskMan.cc
+++ b/lib/TaskMan.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: TaskMan.cc,v 1.53 2008-02-18 00:55:31 pixel Exp $ */
+/* $Id: TaskMan.cc,v 1.54 2008-02-18 09:55:08 pixel Exp $ */
#ifndef _WIN32
#include <signal.h>
@@ -576,6 +576,22 @@ void TaskMan::MainLoop() throw (GeneralException) {
}
}
+ bool got_yield = false;
+ /* Switch all yielded tasks to burning state. */
+ for (TaskList_t::iterator p = TaskList.begin(); p != TaskList.end(); p++) {
+ Task * t = *p;
+
+ if (t->IsStopped()) {
+ continue;
+ }
+
+ if (t->Yielded()) {
+ t->Unyield();
+ }
+
+ got_yield = true;
+ }
+
/* Let's compute the nearest timeout, and run a round trip for expired timeouts. */
int timeout = -1;
event = Task::EVT_TIMEOUT;
@@ -657,12 +673,14 @@ void TaskMan::MainLoop() throw (GeneralException) {
p = w4ha.begin();
}
}
+
+ bool timeout_condition = no_burst && !Zombies.size() && !got_sigchild && !got_yield;
#ifdef _WIN32
- r = poll(ufsd, nfds, (no_burst) && !(Zombies.size()) && !(got_sigchild) ? timeout: 0);
+ r = poll(ufsd, nfds, timeout_condition ? timeout: 0);
#else
sigprocmask(SIG_UNBLOCK, &sigchildset, 0);
- r = poll(ufsd, nfds, (no_burst) && !(Zombies.size()) && !(got_sigchild) ? timeout: 0);
+ r = poll(ufsd, nfds, timeout_condition ? timeout: 0);
sigprocmask(SIG_BLOCK, &sigchildset, 0);
#endif
CleanChildren();
diff --git a/lib/tasklib.lua b/lib/tasklib.lua
index dbd2284..a209ef3 100644
--- a/lib/tasklib.lua
+++ b/lib/tasklib.lua
@@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: tasklib.lua,v 1.7 2008-02-17 00:48:38 pixel Exp $ */
+/* $Id: tasklib.lua,v 1.8 2008-02-18 09:55:08 pixel Exp $ */
]]--
@@ -85,3 +85,7 @@ end
function Command(command, ...)
return coroutine.yield("Command", command, unpack(arg))
end
+
+function TaskYield()
+ return coroutine.yield("Yield")
+end