summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitmodules3
-rw-r--r--Makefile14
-rw-r--r--TODO2
-rw-r--r--includes/Task.h8
-rw-r--r--includes/TaskMan.h12
m---------libcoro0
-rw-r--r--mingw32-config.h1
-rw-r--r--msvc-config.h1
-rw-r--r--src/Task.cc13
-rw-r--r--src/TaskMan.cc4
10 files changed, 26 insertions, 32 deletions
diff --git a/.gitmodules b/.gitmodules
index f01353e..ffbb32a 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,6 +1,3 @@
-[submodule "libcoro"]
- path = libcoro
- url = ../libcoro
[submodule "libev"]
path = libev
url = ../libev
diff --git a/Makefile b/Makefile
index a1e87a2..0271380 100644
--- a/Makefile
+++ b/Makefile
@@ -8,7 +8,7 @@ CPPFLAGS += -g3 -gdwarf-2 -D_DEBUG -DEV_VERIFY=3
LDFLAGS += -g3 -gdwarf-2
endif
-INCLUDES = includes libcoro libev LuaJIT/src lcrypt libtommath libtomcrypt/src/headers src/jsoncpp/include
+INCLUDES = includes libev LuaJIT/src lcrypt libtommath libtomcrypt/src/headers src/jsoncpp/include
LIBS = z curl cares
DEFINES = _LARGEFILE64_SOURCE LITTLE_ENDIAN LTM_DESC LTC_SOURCE USE_LTM
@@ -30,7 +30,7 @@ LDLIBS = $(addprefix -l, $(LIBS))
vpath %.cpp src/jsoncpp/src
vpath %.cc src:tests
-vpath %.c libcoro:libev:win32/pthreads-win32:win32/iconv:win32/regex:lcrypt
+vpath %.c libev:win32/pthreads-win32:win32/iconv:win32/regex:lcrypt
BALAU_SOURCES = \
Exceptions.cc \
@@ -101,12 +101,6 @@ darwin-eprintf.c \
endif
-ifneq ($(SYSTEM),MINGW32)
-LIBCORO_SOURCES = \
-coro.c \
-
-endif
-
LIBEV_SOURCES = \
ev.c \
event.c \
@@ -126,9 +120,9 @@ test-Regex.cc \
LIB = libBalau.a
-BALAU_OBJECTS = $(addsuffix .o, $(notdir $(basename $(BALAU_SOURCES) $(LIBCORO_SOURCES) $(LIBEV_SOURCES) $(WIN32_SOURCES) $(DARWIN_SOURCES))))
+BALAU_OBJECTS = $(addsuffix .o, $(notdir $(basename $(BALAU_SOURCES) $(LIBEV_SOURCES) $(WIN32_SOURCES) $(DARWIN_SOURCES))))
-WHOLE_SOURCES = $(BALAU_SOURCES) $(LIBCORO_SOURCES) $(LIBEV_SOURCES) $(WIN32_SOURCES) $(DARWIN_SOURCES) $(TEST_SOURCES)
+WHOLE_SOURCES = $(BALAU_SOURCES) $(LIBEV_SOURCES) $(WIN32_SOURCES) $(DARWIN_SOURCES) $(TEST_SOURCES)
TESTS = $(addsuffix .$(BINEXT), $(notdir $(basename $(TEST_SOURCES))))
ALL_OBJECTS = $(addsuffix .o, $(notdir $(basename $(WHOLE_SOURCES))))
diff --git a/TODO b/TODO
deleted file mode 100644
index 40b6a13..0000000
--- a/TODO
+++ /dev/null
@@ -1,2 +0,0 @@
-Protect Async against EAgains.
-Add GMP support. \ No newline at end of file
diff --git a/includes/Task.h b/includes/Task.h
index 0f04b32..2577761 100644
--- a/includes/Task.h
+++ b/includes/Task.h
@@ -1,10 +1,10 @@
#pragma once
#include <stdlib.h>
-#include <functional>
-#ifndef _WIN32
-#include <coro.h>
+#ifdef __linux
+#include <ucontext.h>
#endif
+#include <functional>
#include <ev++.h>
#include <list>
#include <Exceptions.h>
@@ -243,7 +243,7 @@ class Task {
}
void * m_stack = NULL;
#ifndef _WIN32
- coro_context m_ctx;
+ ucontext_t m_ctx;
#else
void * m_fiber = NULL;
#endif
diff --git a/includes/TaskMan.h b/includes/TaskMan.h
index ba6d76f..573725f 100644
--- a/includes/TaskMan.h
+++ b/includes/TaskMan.h
@@ -3,9 +3,11 @@
#include <stdint.h>
#include <curl/curl.h>
#ifndef _WIN32
-#include <coro.h>
#include <netdb.h>
#endif
+#ifdef __linux
+#include <ucontext.h>
+#endif
#include <ev++.h>
#ifdef _MSC_VER
#include <hash_set>
@@ -86,10 +88,12 @@ class TaskMan {
void asyncIdleReady() {
m_evt.send();
}
-#ifndef _WIN32
- coro_context m_returnContext;
-#else
+#if defined(__linux)
+ ucontext_t m_returnContext;
+#elif defined (_WIN32)
void * m_fiber;
+#else
+ void * m_returnContext;
#endif
friend class Task;
friend class CurlTask;
diff --git a/libcoro b/libcoro
deleted file mode 160000
-Subproject 348640078e3d991421c6535f3528f6c351ec292
diff --git a/mingw32-config.h b/mingw32-config.h
index fb5a4e8..0e7a0c8 100644
--- a/mingw32-config.h
+++ b/mingw32-config.h
@@ -11,7 +11,6 @@
#define STDC_HEADERS 1
#define WORDS_LITTLEENDIAN 1
-#define CORO_LOSER 1
#define _FILE_OFFSET_BITS 64
#define EMBED_LIBEIO 1
diff --git a/msvc-config.h b/msvc-config.h
index 8e6184c..eb94290 100644
--- a/msvc-config.h
+++ b/msvc-config.h
@@ -16,7 +16,6 @@
#define STDC_HEADERS 1
#define WORDS_LITTLEENDIAN 1
-#define CORO_LOSER 1
#define _FILE_OFFSET_BITS 64
#define EMBED_LIBEIO 1
diff --git a/src/Task.cc b/src/Task.cc
index fe4d97a..949f6de 100644
--- a/src/Task.cc
+++ b/src/Task.cc
@@ -63,7 +63,12 @@ void Balau::Task::setup(TaskMan * taskMan, void * stack) {
#ifndef _WIN32
IAssert(stack, "Can't setup a coroutine without a stack");
m_stack = stack;
- coro_create(&m_ctx, trampoline, this, m_stack, size);
+ int r = getcontext(&m_ctx);
+ RAssert(r == 0, "Unable to get current context: errno = %i", errno);
+ m_ctx.uc_stack.ss_sp = stack;
+ m_ctx.uc_stack.ss_size = size;
+ m_ctx.uc_link = &m_taskMan->m_returnContext;
+ makecontext(&m_ctx, (void(*)()) trampoline, 1, this);
#else
IAssert(!stack, "We shouldn't allocate stacks with Fibers");
m_stack = NULL;
@@ -156,7 +161,7 @@ void Balau::Task::coroutine() {
}
if (!m_stackless) {
#ifndef _WIN32
- coro_transfer(&m_ctx, &m_taskMan->m_returnContext);
+ swapcontext(&m_ctx, &m_taskMan->m_returnContext);
#else
SwitchToFiber(m_taskMan->m_fiber);
#endif
@@ -174,7 +179,7 @@ void Balau::Task::switchTo() {
coroutine();
} else {
#ifndef _WIN32
- coro_transfer(&m_taskMan->m_returnContext, &m_ctx);
+ swapcontext(&m_taskMan->m_returnContext, &m_ctx);
#else
SwitchToFiber(m_fiber);
#endif
@@ -193,7 +198,7 @@ bool Balau::Task::yield(bool stillRunning) {
return true;
} else {
#ifndef _WIN32
- coro_transfer(&m_ctx, &m_taskMan->m_returnContext);
+ swapcontext(&m_ctx, &m_taskMan->m_returnContext);
#else
SwitchToFiber(m_taskMan->m_fiber);
#endif
diff --git a/src/TaskMan.cc b/src/TaskMan.cc
index 6192cf0..288c7ff 100644
--- a/src/TaskMan.cc
+++ b/src/TaskMan.cc
@@ -222,9 +222,7 @@ void Balau::TaskMan::stopMe(int code) {
}
Balau::TaskMan::TaskMan() {
-#ifndef _WIN32
- coro_create(&m_returnContext, 0, 0, 0, 0);
-#else
+#ifdef _WIN32
m_fiber = ConvertThreadToFiber(NULL);
RAssert(m_fiber, "ConvertThreadToFiber returned NULL");
#endif