Skip to content

Commit

Permalink
CORO_PTHREAD compatibility
Browse files Browse the repository at this point in the history
If for some reason UCONTEXT and SJLJ don't work, you can change the
CORO_WHATEVER definition in src/platform.mk to CORO_PTHREAD and it will
use pthreads and pthread_cond_wait to simulate fibers which should be
pretty resilient against v8 changes. This isn't being used for now but
it only needed a few hooks to get this compatibility in.
  • Loading branch information
laverdet committed Aug 13, 2011
1 parent 26b82d2 commit 8b12067
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/coroutine.cc
Expand Up @@ -43,10 +43,16 @@ Coroutine& Coroutine::current() {

void Coroutine::set_stack_size(size_t size) {
assert(!stack_size);
#ifdef CORO_PTHREAD
size += 1024 * 64;
#endif
stack_size = size;
}

void Coroutine::trampoline(void* that) {
#ifdef CORO_PTHREAD
pthread_setspecific(ceil_thread_key, that);
#endif
while (true) {
static_cast<Coroutine*>(that)->entry(const_cast<void*>(static_cast<Coroutine*>(that)->arg));
}
Expand Down Expand Up @@ -85,6 +91,7 @@ void Coroutine::reset(entry_t* entry, void* arg) {

void Coroutine::transfer(Coroutine& next) {
assert(this != &next);
#ifndef CORO_PTHREAD
{
for (pthread_key_t ii = ceil_thread_key - 1; ii > floor_thread_key; --ii) {
// Capture current thread specifics
Expand All @@ -107,8 +114,11 @@ void Coroutine::transfer(Coroutine& next) {
}
}
pthread_setspecific(ceil_thread_key, &next);
#endif
coro_transfer(&context, &next.context);
#ifndef CORO_PTHREAD
pthread_setspecific(ceil_thread_key, this);
#endif
}

void Coroutine::run() {
Expand Down

0 comments on commit 8b12067

Please sign in to comment.