Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix up Windows support

libcoro now has a Windows Fiber backend, so we can remove the custom
code that was handling that.
  • Loading branch information...
commit 247a88d72ed74a25acea163d0f7550247715f6a5 1 parent d22db0a
Marcel Laverdet authored
Showing with 12 additions and 45 deletions.
  1. +1 −1  binding.gyp
  2. +1 −1  build.js
  3. +6 −27 src/coroutine.cc
  4. +4 −16 src/coroutine.h
2  binding.gyp
View
@@ -13,7 +13,7 @@
'cflags!': ['-ansi'],
'conditions': [
['OS == "win"',
- {'defines': ['USE_WINFIBER']},
+ {'defines': ['CORO_FIBER', 'WINDOWS']},
# else
{
'cflags': ['-Wno-deprecated-declarations'],
2  build.js
View
@@ -35,7 +35,7 @@ if (!force) {
// Build it
spawn(
- 'node-gyp',
+ process.platform === 'win32' ? 'node-gyp.cmd' : 'node-gyp',
['rebuild'].concat(args),
{customFds: [0, 1, 2]})
.on('exit', function(err) {
33 src/coroutine.cc
View
@@ -1,9 +1,8 @@
#include "coroutine.h"
#include <assert.h>
-#ifdef USE_CORO
+#ifndef WINDOWS
#include <pthread.h>
-#endif
-#ifdef USE_WINFIBER
+#else
#include <windows.h>
// Pretend Windows TLS is pthreads. Note that pthread_key_create() skips the dtor, but this doesn't
// matter for our application.
@@ -65,7 +64,7 @@ void Coroutine::trampoline(void* that) {
#ifdef CORO_PTHREAD
pthread_setspecific(ceil_thread_key, that);
#endif
-#ifdef USE_WINFIBER
+#ifdef CORO_FIBER
// I can't figure out how to get the precise base of the stack in Windows. Since CreateFiber
// creates the stack automatically we don't have access to the base. We can however grab the
// current esp position, and use that as an approximation. Padding is added for safety since the
@@ -80,37 +79,22 @@ void Coroutine::trampoline(void* that) {
Coroutine::Coroutine() :
entry(NULL),
arg(NULL) {
-#ifdef USE_CORO
stack.sptr = NULL;
coro_create(&context, NULL, NULL, NULL, 0);
-#endif
-#ifdef USE_WINFIBER
- context = ConvertThreadToFiber(NULL);
-#endif
}
Coroutine::Coroutine(entry_t& entry, void* arg) :
entry(entry),
arg(arg) {
-#ifdef USE_CORO
coro_stack_alloc(&stack, stack_size);
coro_create(&context, trampoline, this, stack.sptr, stack.ssze);
-#endif
-#ifdef USE_WINFIBER
- context = CreateFiber(stack_size * sizeof(void*), trampoline, this);
-#endif
}
Coroutine::~Coroutine() {
-#ifdef USE_CORO
if (stack.sptr) {
coro_stack_free(&stack);
}
(void)coro_destroy(&context);
-#endif
-#ifdef USE_WINFIBER
- DeleteFiber(context);
-#endif
}
Coroutine& Coroutine::create_fiber(entry_t* entry, void* arg) {
@@ -156,12 +140,7 @@ void Coroutine::transfer(Coroutine& next) {
}
pthread_setspecific(ceil_thread_key, &next);
#endif
-#ifdef USE_CORO
coro_transfer(&context, &next.context);
-#endif
-#ifdef USE_WINFIBER
- SwitchToFiber(next.context);
-#endif
#ifndef CORO_PTHREAD
pthread_setspecific(ceil_thread_key, this);
#endif
@@ -203,10 +182,10 @@ void Coroutine::finish(Coroutine& next) {
}
void* Coroutine::bottom() const {
-#ifndef USE_WINFIBER
- return stack.sptr;
-#else
+#ifdef CORO_FIBER
return stack_base;
+#else
+ return stack.sptr;
#endif
}
20 src/coroutine.h
View
@@ -1,29 +1,17 @@
#include <stdlib.h>
#include <vector>
-#ifdef USE_CORO
#include "libcoro/coro.h"
-#define TRAMPOLINECALLBACK
-#endif
-#ifdef USE_WINFIBER
-#ifdef CORO_PTHREAD
-#error can not USE_WINFIBER and CORO_PTHREAD
-#endif
-#define TRAMPOLINECALLBACK __stdcall
-#endif
class Coroutine {
public:
typedef void(entry_t)(void*);
private:
-#ifdef USE_CORO
- coro_context context;
- coro_stack stack;
-#endif
-#ifdef USE_WINFIBER
- void* context;
+#ifdef CORO_FIBER
void* stack_base;
#endif
+ coro_context context;
+ coro_stack stack;
std::vector<void*> fls_data;
entry_t* entry;
void* arg;
@@ -48,7 +36,7 @@ class Coroutine {
*/
void reset(entry_t* entry, void* arg);
- static void TRAMPOLINECALLBACK trampoline(void* that);
+ static void trampoline(void* that);
void transfer(Coroutine& next);
public:
Please sign in to comment.
Something went wrong with that request. Please try again.