summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2011-10-18 16:37:49 -0700
committerPixel <pixel@nobis-crew.org>2011-10-18 16:37:49 -0700
commit0db120afdfb818421dc5df3dc0946fafede78c93 (patch)
treee47403f57bcc39471d6c994c4f2951f4eb9ba108 /src
parent4e07ceeb21dae4b6b8d5eaf7421228f735f14bda (diff)
libcoro seems to be doing really spurious things when not using the standard functions.
Switching out libcoro for the native Fibers interface for Win32. Switching out the asm version for the ucontext version for Linux.
Diffstat (limited to 'src')
-rw-r--r--src/Task.cc20
-rw-r--r--src/TaskMan.cc5
2 files changed, 24 insertions, 1 deletions
diff --git a/src/Task.cc b/src/Task.cc
index 558b7de..ad481cc 100644
--- a/src/Task.cc
+++ b/src/Task.cc
@@ -8,8 +8,13 @@ static Balau::LocalTmpl<Balau::Task> localTask;
Balau::Task::Task() {
size_t size = stackSize();
+#ifndef _WIN32
m_stack = malloc(size);
coro_create(&m_ctx, coroutine, this, m_stack, size);
+#else
+ m_stack = NULL;
+ m_fiber = CreateFiber(size, coroutine, this);
+#endif
m_taskMan = TaskMan::getTaskMan();
m_taskMan->registerTask(this);
@@ -27,7 +32,8 @@ Balau::Task::Task() {
}
Balau::Task::~Task() {
- free(m_stack);
+ if (m_stack)
+ free(m_stack);
free(m_tls);
}
@@ -48,7 +54,11 @@ void Balau::Task::coroutine(void * arg) {
Printer::log(M_WARNING, "Task %s at %p caused an unknown exception - stopping.", task->getName(), task);
task->m_status = FAULTED;
}
+#ifndef _WIN32
coro_transfer(&task->m_ctx, &task->m_taskMan->m_returnContext);
+#else
+ SwitchToFiber(task->m_taskMan->m_fiber);
+#endif
}
void Balau::Task::switchTo() {
@@ -56,7 +66,11 @@ void Balau::Task::switchTo() {
Assert(m_status == IDLE || m_status == STARTING);
void * oldTLS = g_tlsManager->getTLS();
g_tlsManager->setTLS(m_tls);
+#ifndef _WIN32
coro_transfer(&m_taskMan->m_returnContext, &m_ctx);
+#else
+ SwitchToFiber(m_fiber);
+#endif
g_tlsManager->setTLS(oldTLS);
if (m_status == RUNNING)
m_status = IDLE;
@@ -64,7 +78,11 @@ void Balau::Task::switchTo() {
void Balau::Task::yield() {
Printer::elog(E_TASK, "Task %p - %s yielding", this, getName());
+#ifndef _WIN32
coro_transfer(&m_ctx, &m_taskMan->m_returnContext);
+#else
+ SwitchToFiber(m_taskMan->m_fiber);
+#endif
}
Balau::Task * Balau::Task::getCurrentTask() {
diff --git a/src/TaskMan.cc b/src/TaskMan.cc
index fc33530..0fc4668 100644
--- a/src/TaskMan.cc
+++ b/src/TaskMan.cc
@@ -7,7 +7,12 @@ static Balau::DefaultTmpl<Balau::TaskMan> defaultTaskMan(50);
static Balau::LocalTmpl<Balau::TaskMan> localTaskMan;
Balau::TaskMan::TaskMan() : m_stopped(false), m_allowedToSignal(false) {
+#ifndef _WIN32
coro_create(&m_returnContext, 0, 0, 0, 0);
+#else
+ m_fiber = ConvertThreadToFiber(NULL);
+ Assert(m_fiber);
+#endif
if (!localTaskMan.getGlobal()) {
localTaskMan.setGlobal(this);
m_loop = ev_default_loop(EVFLAG_AUTO);