summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/Task.h3
-rw-r--r--includes/TaskMan.h2
-rw-r--r--src/Task.cc12
-rw-r--r--src/TaskMan.cc8
4 files changed, 22 insertions, 3 deletions
diff --git a/includes/Task.h b/includes/Task.h
index 9244347..5865831 100644
--- a/includes/Task.h
+++ b/includes/Task.h
@@ -135,8 +135,9 @@ class Task {
}
TaskMan * getMyTaskMan() { return m_taskMan; }
private:
- size_t stackSize() { return 128 * 1024; }
+ static size_t stackSize() { return 64 * 1024; }
void setup(TaskMan * taskMan);
+ static bool needsStacks();
void switchTo();
static void CALLBACK coroutineTrampoline(void *);
void coroutine();
diff --git a/includes/TaskMan.h b/includes/TaskMan.h
index 6d005ef..b944f09 100644
--- a/includes/TaskMan.h
+++ b/includes/TaskMan.h
@@ -35,6 +35,8 @@ class TaskMan {
void stopMe() { m_stopped = true; }
private:
static void registerTask(Task * t, Task * stick);
+ void * getStack();
+ void freeStack(void * stack);
void addToPending(Task * t);
#ifndef _WIN32
coro_context m_returnContext;
diff --git a/src/Task.cc b/src/Task.cc
index b512e23..d72decc 100644
--- a/src/Task.cc
+++ b/src/Task.cc
@@ -13,10 +13,18 @@ Balau::Task::Task() {
Printer::elog(E_TASK, "Created a Task at %p");
}
+bool Balau::Task::needsStacks() {
+#ifndef _WIN32
+ return true;
+#else
+ return false;
+#endif
+}
+
void Balau::Task::setup(TaskMan * taskMan) {
size_t size = stackSize();
#ifndef _WIN32
- m_stack = malloc(size);
+ m_stack = taskMan->getStack();
coro_create(&m_ctx, coroutineTrampoline, this, m_stack, size);
#else
m_stack = NULL;
@@ -34,7 +42,7 @@ void Balau::Task::setup(TaskMan * taskMan) {
Balau::Task::~Task() {
if (m_stack)
- free(m_stack);
+ m_taskMan->freeStack(m_stack);
free(m_tls);
}
diff --git a/src/TaskMan.cc b/src/TaskMan.cc
index 375a94d..e9e3485 100644
--- a/src/TaskMan.cc
+++ b/src/TaskMan.cc
@@ -134,6 +134,14 @@ Balau::TaskMan::~TaskMan() {
ev_loop_destroy(m_loop);
}
+void * Balau::TaskMan::getStack() {
+ return malloc(Task::stackSize());
+}
+
+void Balau::TaskMan::freeStack(void * stack) {
+ free(stack);
+}
+
void Balau::TaskMan::mainLoop() {
// We need at least one round before bailing :)
do {