From 7b3f9f74fb9bd764c1382849b9d66eb50ccf4e17 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Sat, 4 Apr 2015 11:18:21 +0200 Subject: Removing libcoro. --- .gitmodules | 3 --- Makefile | 14 ++++---------- TODO | 2 -- includes/Task.h | 8 ++++---- includes/TaskMan.h | 12 ++++++++---- libcoro | 1 - mingw32-config.h | 1 - msvc-config.h | 1 - src/Task.cc | 13 +++++++++---- src/TaskMan.cc | 4 +--- 10 files changed, 26 insertions(+), 33 deletions(-) delete mode 100644 TODO delete mode 160000 libcoro 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 -#include -#ifndef _WIN32 -#include +#ifdef __linux +#include #endif +#include #include #include #include @@ -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 #include #ifndef _WIN32 -#include #include #endif +#ifdef __linux +#include +#endif #include #ifdef _MSC_VER #include @@ -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 index 3486400..0000000 --- a/libcoro +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 348640078e3d991421c6535f3528f6c351ec2922 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 -- cgit v1.2.3