summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2012-04-08 16:33:53 -0700
committerPixel <pixel@nobis-crew.org>2012-04-08 16:33:53 -0700
commit1548da7eb85e8199e49c0a4e7e3c53fb2184177e (patch)
tree03ab0059404f3fd0b985853a166be1293b071ce9
parent0fb5f42ca43f11bd37ddc89aa7c7b098d764b28c (diff)
Few more quirks into the stackless mode; we don't want to allocate stacks nor create any co-routine (or fiber) if we're stackless.
-rw-r--r--includes/Task.h1
-rw-r--r--src/Task.cc19
-rw-r--r--src/TaskMan.cc7
3 files changed, 17 insertions, 10 deletions
diff --git a/includes/Task.h b/includes/Task.h
index b5f5540..e9c2add 100644
--- a/includes/Task.h
+++ b/includes/Task.h
@@ -153,6 +153,7 @@ class Task {
static void yield(Events::BaseEvent * evt, bool interruptible = false) throw (GeneralException);
TaskMan * getTaskMan() const { return m_taskMan; }
struct ev_loop * getLoop();
+ bool isStackless() { return m_stackless; }
protected:
void yield(bool stillRunning = false) throw (GeneralException);
virtual void Do() = 0;
diff --git a/src/Task.cc b/src/Task.cc
index 5026d28..52e9fa2 100644
--- a/src/Task.cc
+++ b/src/Task.cc
@@ -19,16 +19,21 @@ bool Balau::Task::needsStacks() {
}
void Balau::Task::setup(TaskMan * taskMan, void * stack) {
- size_t size = stackSize();
+ if (m_stackless) {
+ IAssert(!stack, "Since we're stackless, no stack should've been allocated.");
+ m_stack = NULL;
+ } else {
+ size_t size = stackSize();
#ifndef _WIN32
- IAssert(stack, "Can't setup a coroutine without a stack");
- m_stack = stack;
- coro_create(&m_ctx, coroutineTrampoline, this, m_stack, size);
+ IAssert(stack, "Can't setup a coroutine without a stack");
+ m_stack = stack;
+ coro_create(&m_ctx, coroutineTrampoline, this, m_stack, size);
#else
- Assert(!stack, "We shouldn't allocate stacks with Fibers");
- m_stack = NULL;
- m_fiber = CreateFiber(size, coroutineTrampoline, this);
+ Assert(!stack, "We shouldn't allocate stacks with Fibers");
+ m_stack = NULL;
+ m_fiber = CreateFiber(size, coroutineTrampoline, this);
#endif
+ }
m_taskMan = taskMan;
diff --git a/src/TaskMan.cc b/src/TaskMan.cc
index 048b27a..33d07d0 100644
--- a/src/TaskMan.cc
+++ b/src/TaskMan.cc
@@ -192,10 +192,11 @@ Balau::TaskMan::~TaskMan() {
}
void * Balau::TaskMan::getStack() {
+ if (!Task::needsStacks())
+ return NULL;
void * r = NULL;
if (m_nStacks == 0) {
- if (Task::needsStacks())
- r = malloc(Task::stackSize());
+ r = malloc(Task::stackSize());
} else {
r = m_stacks.front();
m_stacks.pop();
@@ -298,7 +299,7 @@ int Balau::TaskMan::mainLoop() {
Printer::elog(E_TASK, "TaskMan at %p popped task %p...", this, t);
IAssert(m_tasks.find(t) == m_tasks.end(), "TaskMan got task %p twice... ?", t);
ev_now_update(m_loop);
- t->setup(this, getStack());
+ t->setup(this, t->isStackless() ? NULL : getStack());
m_tasks.insert(t);
starting.insert(t);
}