From 9b6dc4d5d83f8acbd82459a0296eb256f632ea02 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Fri, 2 Aug 2013 10:25:47 +0200 Subject: Adding the SimpleContext class that switches the current Task from complex to simple. --- includes/Task.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'includes') 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; -- cgit v1.2.3