summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorNicolas "Pixel" Noble <pixel@nobis-crew.org>2013-08-02 10:25:47 +0200
committerNicolas "Pixel" Noble <pixel@nobis-crew.org>2013-08-02 10:25:47 +0200
commit9b6dc4d5d83f8acbd82459a0296eb256f632ea02 (patch)
treeffd50ef2acc012cf7382d945169a01dd6a92a23b /includes
parent6d956657c4612e988f89a133cea93e50ec2dcb39 (diff)
Adding the SimpleContext class that switches the current Task from complex to simple.
Diffstat (limited to 'includes')
-rw-r--r--includes/Task.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/includes/Task.h b/includes/Task.h
index 26d2c65..e8aea70 100644
--- a/includes/Task.h
+++ b/includes/Task.h
@@ -166,6 +166,13 @@ class Task {
TaskMan * getTaskMan() const { return m_taskMan; }
struct ev_loop * getLoop();
bool isStackless() { return m_stackless; }
+ class SimpleContext {
+ public:
+ SimpleContext() : m_oldStatus(Task::getCurrentTask()->enterSimpleContext()) { }
+ ~SimpleContext() { Task::getCurrentTask()->leaveSimpleContext(m_oldStatus); }
+ private:
+ bool m_oldStatus;
+ };
protected:
void yield() throw (GeneralException) {
if (yield(false))
@@ -201,6 +208,15 @@ class Task {
void switchTo();
static void CALLBACK coroutineTrampoline(void *);
void coroutine();
+ bool enterSimpleContext() {
+ AAssert(!m_stackless, "You can't enter a simple context in a stackless task");
+ bool r = m_okayToEAgain;
+ m_okayToEAgain = false;
+ return r;
+ }
+ void leaveSimpleContext(bool oldStatus) {
+ m_okayToEAgain = oldStatus;
+ }
void * m_stack = NULL;
#ifndef _WIN32
coro_context m_ctx;