diff --git a/ACKNOWLEDGEMENTS b/ACKNOWLEDGEMENTS index 8a524b9cd7e..0f5ef7879b5 100644 --- a/ACKNOWLEDGEMENTS +++ b/ACKNOWLEDGEMENTS @@ -27,64 +27,10 @@ Mark Adler, Robert Važan (CRC-32C [Castagnoli] for C++ and .NET) 3. This notice may not be removed or altered from any source distribution. -Russ Cox (asm.S from libcoroutine) - This software was developed as part of a project at MIT. - - Copyright (c) 2005-2007 Russ Cox, - Massachusetts Institute of Technology - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - Beman Dawes, Christopher M. Kohlhoff (Boost) The Boost License (http://www.boost.org/users/license.html) does not require attribution or republication when Boost is redistributed in object code form. -Steve Dekorte (libcoroutine) - Copyright (c) 2002, 2003 Steve Dekorte - All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - Â¥ Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - Â¥ Redistributions in binary form must reproduce the above copyright notice, this - list of conditions and the following disclaimer in the documentation and/or - other materials provided with the distribution. - - Â¥ Neither the name of the author nor the names of other contributors may be used - to endorse or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - The Go Authors (Go Tools) Copyright (c) 2009 The Go Authors. All rights reserved. diff --git a/cmake/FDBComponents.cmake b/cmake/FDBComponents.cmake index d305f48eb6c..9b1671ec3db 100644 --- a/cmake/FDBComponents.cmake +++ b/cmake/FDBComponents.cmake @@ -199,21 +199,6 @@ else() target_include_directories(toml11_target SYSTEM INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/toml11/include) endif() -################################################################################ -# Coroutine implementation -################################################################################ - -set(DEFAULT_COROUTINE_IMPL boost) -if(WIN32) - # boost coroutine not available in windows build environment for now. - set(DEFAULT_COROUTINE_IMPL libcoro) -elseif(NOT APPLE AND NOT USE_ASAN AND CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^x86") - # revert to libcoro for x86 linux while we investigate a performance regression - set(DEFAULT_COROUTINE_IMPL libcoro) -endif() - -set(COROUTINE_IMPL ${DEFAULT_COROUTINE_IMPL} CACHE STRING "Which coroutine implementation to use. Options are boost and libcoro") - ################################################################################ # AWS SDK ################################################################################ diff --git a/contrib/apiversioner.py b/contrib/apiversioner.py index 4c3e7d35c9d..d0f62fdf00c 100755 --- a/contrib/apiversioner.py +++ b/contrib/apiversioner.py @@ -80,7 +80,6 @@ r"fdbrpc/zlib/.*", r"fdbrpc/sha1/.*", r"fdbrpc/xml2json.hpp$", - r"fdbrpc/libcoroutine/.*", r"fdbrpc/libeio/.*", r"fdbrpc/lib64/.*", r"fdbrpc/generated-constants.cpp$", diff --git a/fdbrpc/CMakeLists.txt b/fdbrpc/CMakeLists.txt index bc9b4c5490e..abd209a571f 100644 --- a/fdbrpc/CMakeLists.txt +++ b/fdbrpc/CMakeLists.txt @@ -42,39 +42,12 @@ if(COMPILE_EIO) target_compile_options(eio BEFORE PRIVATE -w) # disable warnings for eio endif() -if(${COROUTINE_IMPL} STREQUAL libcoro) - set(CORO_SRCS libcoroutine/Common.c libcoroutine/Coro.c) - if(APPLE) - list(APPEND CORO_SRCS libcoroutine/asm.S) - endif() - if(NOT WIN32) - list(APPEND CORO_SRCS libcoroutine/context.c) - endif() - add_library(coro STATIC ${CORO_SRCS}) - target_link_libraries(coro PRIVATE flow) - target_include_directories(coro PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/libcoroutine) - if(WIN32) - target_compile_definitions(coro PRIVATE USE_FIBERS) - else() - target_compile_definitions(coro PRIVATE USE_UCONTEXT) - target_compile_options(coro BEFORE PRIVATE -w) # disable warnings for third party - endif() - if(USE_VALGRIND) - target_link_libraries(coro PUBLIC Valgrind) - endif() -endif() - target_include_directories(fdbrpc PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/include" PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/libeio) target_link_libraries(fdbrpc PUBLIC flow libb64 md5 PRIVATE rapidjson) target_include_directories(fdbrpc_sampling PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/include" PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/libeio) target_link_libraries(fdbrpc_sampling PUBLIC flow_sampling libb64 md5 PRIVATE rapidjson) -if(${COROUTINE_IMPL} STREQUAL libcoro) - target_link_libraries(fdbrpc PUBLIC coro) - target_link_libraries(fdbrpc_sampling PUBLIC coro) -endif() - if(COMPILE_EIO) target_link_libraries(fdbrpc PRIVATE eio) target_link_libraries(fdbrpc_sampling PRIVATE eio) @@ -86,4 +59,4 @@ if(WIN32) add_dependencies(tokensign_actors fdbrpc_actors) endif() -add_subdirectory(tests) \ No newline at end of file +add_subdirectory(tests) diff --git a/fdbrpc/libcoroutine/386-ucontext.h b/fdbrpc/libcoroutine/386-ucontext.h deleted file mode 100644 index 1c69acec567..00000000000 --- a/fdbrpc/libcoroutine/386-ucontext.h +++ /dev/null @@ -1,119 +0,0 @@ -#define setcontext(u) setmcontext(&(u)->uc_mcontext) -#define getcontext(u) getmcontext(&(u)->uc_mcontext) -typedef struct mcontext mcontext_t; -typedef struct ucontext ucontext_t; - -extern int swapcontext(ucontext_t*, const ucontext_t*); -extern void makecontext(ucontext_t*, void (*)(void), int, ...); -extern int getmcontext(mcontext_t*); -extern void setmcontext(const mcontext_t*); - -/*- - * Copyright (c) 1999 Marcel Moolenaar - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer - * in this position and unchanged. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD: src/sys/sys/ucontext.h,v 1.4 1999/10/11 20:33:17 luoqi Exp $ - */ - -/* #include */ - -/*- - * Copyright (c) 1999 Marcel Moolenaar - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer - * in this position and unchanged. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD: src/sys/i386/include/ucontext.h,v 1.4 1999/10/11 20:33:09 luoqi Exp $ - */ - -struct mcontext { - /* - * The first 20 fields must match the definition of - * sigcontext. So that we can support sigcontext - * and ucontext_t at the same time. - */ - int mc_onstack; /* XXX - sigcontext compat. */ - int mc_gs; - int mc_fs; - int mc_es; - int mc_ds; - int mc_edi; - int mc_esi; - int mc_ebp; - int mc_isp; - int mc_ebx; - int mc_edx; - int mc_ecx; - int mc_eax; - int mc_trapno; - int mc_err; - int mc_eip; - int mc_cs; - int mc_eflags; - int mc_esp; /* machine state */ - int mc_ss; - - int mc_fpregs[28]; /* env87 + fpacc87 + u_long */ - int __spare__[17]; -}; - -struct ucontext { - /* - * Keep the order of the first two fields. Also, - * keep them the first two fields in the structure. - * This way we can have a union with struct - * sigcontext and ucontext_t. This allows us to - * support them both at the same time. - * note: the union is not defined, though. - */ - sigset_t uc_sigmask; - mcontext_t uc_mcontext; - - struct __ucontext* uc_link; - stack_t uc_stack; - int __spare__[8]; -}; diff --git a/fdbrpc/libcoroutine/Base.h b/fdbrpc/libcoroutine/Base.h deleted file mode 100644 index c332ffb0506..00000000000 --- a/fdbrpc/libcoroutine/Base.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef IOBASE_DEFINED -#define IOBASE_DEFINED 1 - -#include -#include -#include -#include -#include -#include -#include -#include - -#endif diff --git a/fdbrpc/libcoroutine/Common.c b/fdbrpc/libcoroutine/Common.c deleted file mode 100644 index 81bb3c40b1d..00000000000 --- a/fdbrpc/libcoroutine/Common.c +++ /dev/null @@ -1,289 +0,0 @@ -// metadoc Common copyright Steve Dekorte 2002 -// metadoc Common license BSD revised - -#include "Common.h" -#include - -#ifdef IO_CHECK_ALLOC - -static long allocs = 0; -static long reallocs = 0; -static long allocatedBytes = 0; -static long maxAllocatedBytes = 0; -static long frees = 0; - -/* -typedef struct -{ - long allocs = 0; - long reallocs = 0; - long allocatedBytes = 0; - long maxAllocatedBytes = 0; - long frees = 0; -} Allocator; - -Allocator *Allocator_new(void) -{ - Allocator *self = calloc(1, sizeof(Allocator)); - return self; -} - -void Allocator_free(Allocator *self) -{ - free(self); -} - -size_t Allocator_allocs(Allocator *self) -{ - return self->allocs; -} - -size_t Allocator_frees(Allocator *self) -{ - return self->frees; -} - -size_t Allocator_allocatedBytes(Allocator *self) -{ - return self->allocatedBytes; -} - -size_t Allocator_maxAllocatedBytes(Allocator *self) -{ - return self->maxAllocatedBytes; -} - -void Allocator_resetMaxAllocatedBytes(Allocator *self) -{ - self->maxAllocatedBytes = self->allocatedBytes; -} - -void Allocator_show(Allocator *self) -{ - printf("allocs %i\n", self->allocs); - printf("reallocs %i\n", self->reallocs); - printf("frees %i\n", self->frees); - printf("allocsMinusfrees %i\n", self->allocs - self->frees); - printf("allocatedBytes %i\n", self->allocatedBytes); - printf("maxAllocatedBytes %i\n", self->maxAllocatedBytes); - //printf("allocs %i bytes %i\n", self->allocs, self->allocatedBytes); -} - -static Allocator *_globalAllocator; - -Allocator *globalAllocator(void) -{ - if(!_globalAllocator) Allocator_new(); - return _globalAllocator; -} -*/ - -// ------------------------------------------------------- - -typedef struct MemoryBlock MemoryBlock; - -struct MemoryBlock { - size_t size; - size_t allocNum; - char* file; - int line; - MemoryBlock* next; - MemoryBlock* prev; - char padding[40 - (sizeof(size_t) + sizeof(size_t) + sizeof(char*) + sizeof(int) + sizeof(void*) + sizeof(void*))]; -}; - -MemoryBlock* PtrToMemoryBlock(void* ptr) { - return (MemoryBlock*)(((char*)ptr) - sizeof(MemoryBlock)); -} - -void* MemoryBlockToPtr(MemoryBlock* self) { - return (void*)(((char*)self) + sizeof(MemoryBlock)); -} - -static MemoryBlock* _baseblock = NULL; - -// inline -MemoryBlock* baseblock(void) { - if (!_baseblock) - _baseblock = calloc(1, sizeof(MemoryBlock)); - return _baseblock; -} - -void MemoryBlock_remove(MemoryBlock* self) { - if (self->next) - self->next->prev = self->prev; - if (self->prev) - self->prev->next = self->next; -} - -void MemoryBlock_insertAfter_(MemoryBlock* self, MemoryBlock* other) { - self->next = other->next; - self->prev = other; - other->next = self; - if (self->next) - self->next->prev = self; -} - -MemoryBlock* MemoryBlock_newWithSize_file_line_(size_t size, char* file, int line) { - MemoryBlock* self = calloc(1, sizeof(MemoryBlock) + size); - self->size = size; - self->allocNum = allocs; - self->file = file; - self->line = line; - MemoryBlock_insertAfter_(self, baseblock()); - - allocs++; - allocatedBytes += size; - if (allocatedBytes > maxAllocatedBytes) - maxAllocatedBytes = allocatedBytes; - return self; -} - -MemoryBlock* MemoryBlock_reallocToSize_(MemoryBlock* self, size_t size) { - MemoryBlock* prev = self->prev; - MemoryBlock_remove(self); - allocatedBytes -= self->size; - allocatedBytes += size; - reallocs++; - self = realloc(self, sizeof(MemoryBlock) + size); - self->size = size; - MemoryBlock_insertAfter_(self, prev); - return self; -} - -void MemoryBlock_free(MemoryBlock* self) { - MemoryBlock_remove(self); - allocatedBytes -= self->size; - frees++; - free(self); -} - -size_t MemoryBlock_size(MemoryBlock* self) { - return self->size; -} - -void MemoryBlock_show(MemoryBlock* self) { - char* file = strrchr(self->file, '/'); - file = file ? file + 1 : self->file; - // printf(" MemoryBlock %p:\n", (void *)self); - // printf("\tsize %i\n", self->size); - // printf("\tfile %s\n", file); - // printf("\tline %i\n", self->line); - printf("\t%i %p %s:%i\t\t%i bytes\n", self->allocNum, MemoryBlockToPtr(self), file, self->line, self->size); -} - -// ---------------------------------------------------------------------------- - -void* io_real_malloc(size_t size, char* file, int line) { - MemoryBlock* m = MemoryBlock_newWithSize_file_line_(size, file, line); - return MemoryBlockToPtr(m); -} - -void* io_real_calloc(size_t count, size_t size, char* file, int line) { - return io_real_malloc(count * size, file, line); -} - -void* io_real_realloc(void* ptr, size_t size, char* file, int line) { - if (ptr) { - MemoryBlock* m = MemoryBlock_reallocToSize_(PtrToMemoryBlock(ptr), size); - return MemoryBlockToPtr(m); - } - - return io_real_malloc(size, file, line); -} - -void io_free(void* ptr) { - MemoryBlock_free(PtrToMemoryBlock(ptr)); -} - -// -------------------------------------------------------------------------- - -void io_show_mem(char* s) { - printf("\n--- %s ---\n", s ? s : ""); - printf("allocs %i\n", allocs); - printf("reallocs %i\n", reallocs); - printf("frees %i\n", frees); - printf("allocsMinusfrees %i\n", allocs - frees); - printf("allocatedBytes %i\n", allocatedBytes); - printf("maxAllocatedBytes %i\n", maxAllocatedBytes); - // printf("allocs %i bytes %i\n", allocs, allocatedBytes); - // printf("\n"); -} - -size_t io_maxAllocatedBytes(void) { - return maxAllocatedBytes; -} - -void io_resetMaxAllocatedBytes(void) { - maxAllocatedBytes = allocatedBytes; -} - -size_t io_frees(void) { - return frees; -} - -size_t io_allocatedBytes(void) { - return allocatedBytes; -} - -size_t io_allocs(void) { - return allocs; -} - -void io_showUnfreed(void) { - MemoryBlock* m = baseblock()->next; - size_t sum = 0; - int n = 0; - - while (m) { - MemoryBlock_show(m); - sum += m->size; - n++; - m = m->next; - } - - printf("\n %i bytes in %i blocks\n", (int)sum, n); -} - -#endif - -void* cpalloc(const void* p, size_t size) { - void* n = io_malloc(size); - if (p) - memcpy(n, p, size); - return n; -} - -void* io_freerealloc(void* p, size_t size) { - return realloc(p, size); - /* - void *n = io_malloc(size); - - if (p != NULL) - { - memcpy(n, p, size); - free(p); - } - - return n; - */ -} - -int io_isBigEndian(void) { - int i = 0x1; - uint8_t* s = (uint8_t*)(&i); - return s[0]; -} - -uint32_t io_uint32InBigEndian(uint32_t i) { - uint32_t o; - uint8_t* os = (uint8_t*)&o; - uint8_t* is = (uint8_t*)&i; - if (io_isBigEndian()) - return i; - os[0] = is[3]; - os[1] = is[2]; - os[2] = is[1]; - os[3] = is[0]; - return o; -} diff --git a/fdbrpc/libcoroutine/Common.h b/fdbrpc/libcoroutine/Common.h deleted file mode 100644 index 70d7f825b1e..00000000000 --- a/fdbrpc/libcoroutine/Common.h +++ /dev/null @@ -1,196 +0,0 @@ - -// metadoc Common copyright Steve Dekorte 2002 -// metadoc Common license BSD revised -/*metadoc Common description -This is a header that all other source files should include. -These defines are helpful for doing OS specific checks in the code. - */ - -#ifndef IOCOMMON_DEFINED -#define IOCOMMON_DEFINED 1 - -/*#define LOW_MEMORY_SYSTEM 1*/ -#include -#include -#include - -#if defined(__SVR4) && defined(__sun) -#include -#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) -#include -#elif !defined(__SYMBIAN32__) && !defined(__NeXT__) -#include -#else -typedef unsigned char uint8_t; -typedef signed char int8_t; -typedef unsigned short uint16_t; -typedef signed short int16_t; -typedef unsigned long uint32_t; -typedef signed long int32_t; -/* - typedef unsigned long uint64_t; - typedef signed long int64_t; - */ -typedef unsigned long long uint64_t; -typedef long long int64_t; -#endif - -/* Windows stuff */ - -#if defined(WIN32) || defined(__WINS__) || defined(__MINGW32__) || defined(_MSC_VER) -#define inline __inline -// #define snprintf _snprintf -#define usleep(x) Sleep(((x) + 999) / 1000) - -#define HAS_FIBERS 1 - -#define ON_WINDOWS 1 - -// this also includes windows.h -#include - -// Enable fibers -#ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0400 -#endif - -#if !defined(__MINGW32__) && 0 -#if defined(BUILDING_BASEKIT_DLL) || defined(BUILDING_IOVMALL_DLL) -#define BASEKIT_API __declspec(dllexport) -#else -#define BASEKIT_API __declspec(dllimport) -#endif -#else -#define BASEKIT_API -#endif -/* -#ifndef _SYS_STDINT_H_ -#include "PortableStdint.h" -#endif - */ - -#if !defined(__MINGW32__) -/* disable compile warnings which are always treated -as errors in my dev settings */ - -#pragma warning(disable : 4244) -/* warning C4244: 'function' : conversion from 'double ' to 'int ', possible loss of data */ - -#pragma warning(disable : 4996) -/* warning C4996: 'function' : This function or variable may be unsafe. Consider using 'function_s' instead */ - -#pragma warning(disable : 4018) -/* warning C4018: 'operator' : signed/unsigned mismatch */ - -/*#pragma warning( disable : 4090 ) */ -/* warning C4090: 'function' : different 'const' qualifiers */ - -/*#pragma warning( disable : 4024 )*/ -/* warning C4024: different types for formal and actual parameter */ - -/*#pragma warning( disable : 4761 ) */ -/* warning C4761: integral size mismatch in argument; conversion supplied */ - -/*#pragma warning( disable : 4047 ) */ -/* warning C4047: '=' : 'char *' differs in levels of indirection from 'int ' */ -#define ARCHITECTURE_x86 1 -#endif - -/* io_malloc, io_realloc, io_free undefined */ -#if !defined(__SYMBIAN32__) -#include - -/* strlen undefined */ -#include -#include /* for calloc */ -#endif -#else - -// Not on windows so define this away -#define BASEKIT_API - -#endif - -/* - [DBCS Enabling] - - DBCS (Short for Double-Byte Character Set), a character set that uses two-byte (16-bit) characters. Some languages, - such as Chinese, Japanese and Korean (CJK), have writing schemes with many different characters that cannot be - represented with single-byte codes such as ASCII and EBCDIC. - - In CJK world, CES (Character Encoding Scheme) and CCS (Coded Character Set) are actually different concept(one CES may - contain multiple CCS). For example, EUC-JP is a CES which includes CCS of ASCII and JIS X 0208 (optionally JIS X 0201 - Kana and JIS X 0212). - - In Japanese (because I am Japanese), - While EUC-JP and UTF-8 Map ASCII unchanged, ShiftJIS not (However ShiftJIS is de facto standard in Japan). For example, - {0x95, 0x5c} represents one character. in ASCII, second byte(0x5c) is back slash character. - */ - -/* - check whether double-byte character. supported only ShiftJIS. - if you want to use ShiftJIS characters in string literal, set compiler option -DDBCS_ENABLED=1. - */ - -#if DBCS_ENABLED -#define ismbchar(c) ISSJIS((unsigned char)c) -#define mbcharlen(c) 2 -#define ISSJIS(c) ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xfc)) -#else -#define ismbchar(c) 0 -#define mbcharlen(c) 1 -#endif /* DBCS_ENABLED */ - -#ifdef __cplusplus -extern "C" { -#endif - -// #define IO_CHECK_ALLOC ENABLED(NOT_IN_CLEAN) - -#ifdef IO_CHECK_ALLOC -BASEKIT_API size_t io_memsize(void* ptr); - -#define io_malloc(size) io_real_malloc(size, __FILE__, __LINE__) -BASEKIT_API void* io_real_malloc(size_t size, char* file, int line); - -#define io_calloc(count, size) io_real_calloc(count, size, __FILE__, __LINE__) -BASEKIT_API void* io_real_calloc(size_t count, size_t size, char* file, int line); - -#define io_realloc(ptr, size) io_real_realloc(ptr, size, __FILE__, __LINE__) -BASEKIT_API void* io_real_realloc(void* ptr, size_t newSize, char* file, int line); - -BASEKIT_API void io_free(void* ptr); -BASEKIT_API void io_show_mem(char* s); -BASEKIT_API size_t io_maxAllocatedBytes(void); -BASEKIT_API void io_resetMaxAllocatedBytes(void); -BASEKIT_API size_t io_frees(void); -BASEKIT_API size_t io_allocs(void); -BASEKIT_API size_t io_allocatedBytes(void); - -BASEKIT_API void io_showUnfreed(void); -#else -#define io_memsize -#define io_malloc malloc -#define io_calloc calloc -#define io_realloc io_freerealloc -#define io_free free -#define io_show_mem - -#define io_maxAllocatedBytes() 0 -#define io_frees() 0 -#define io_allocs() 0 -#define io_allocatedBytes() 0 -#define io_resetMaxAllocatedBytes() -#endif - -BASEKIT_API void* cpalloc(const void* p, size_t size); -BASEKIT_API void* io_freerealloc(void* p, size_t size); - -int io_isBigEndian(void); -BASEKIT_API uint32_t io_uint32InBigEndian(uint32_t i); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/fdbrpc/libcoroutine/Coro.c b/fdbrpc/libcoroutine/Coro.c deleted file mode 100644 index 8e7244a2aa8..00000000000 --- a/fdbrpc/libcoroutine/Coro.c +++ /dev/null @@ -1,745 +0,0 @@ -/* - Credits - - Originally based on Edgar Toernig's Minimalistic cooperative multitasking - http://www.goron.de/~froese/ - reorg by Steve Dekorte and Chis Double - Symbian and Cygwin support by Chis Double - Linux/PCC, Linux/Opteron, Irix and FreeBSD/Alpha, ucontext support by Austin Kurahone - FreeBSD/Intel support by Faried Nawaz - Mingw support by Pit Capitain - Visual C support by Daniel Vollmer - Solaris support by Manpreet Singh - Fibers support by Jonas Eschenburg - Ucontext arg support by Olivier Ansaldi - Ucontext x86-64 support by James Burgess and Jonathan Wright - Russ Cox for the newer portable ucontext implementations. - - Notes - - This is the system dependent coro code. - Setup a jmp_buf so when we longjmp, it will invoke 'func' using 'stack'. - Important: 'func' must not return! - - Usually done by setting the program counter and stack pointer of a new, empty stack. - If you're adding a new platform, look in the setjmp.h for PC and SP members - of the stack structure - - If you don't see those members, Kentaro suggests writing a simple - test app that calls setjmp and dumps out the contents of the jmp_buf. - (The PC and SP should be in jmp_buf->__jmpbuf). - - Using something like GDB to be able to peek into register contents right - before the setjmp occurs would be helpful also. - */ - -#include "Common.h" -#include "flow/Platform.h" -#include "Base.h" -#include "Coro.h" -#include -#include -#include -#include - -#include - -#ifndef WIN32 -#include "taskimpl.h" -#endif - -#ifdef USE_VALGRIND -#include -#define STACK_REGISTER(coro) \ - { \ - Coro* c = (coro); \ - c->valgrindStackId = VALGRIND_STACK_REGISTER(c->stack, c->stack + c->requestedStackSize); \ - } - -#define STACK_DEREGISTER(coro) VALGRIND_STACK_DEREGISTER((coro)->valgrindStackId) - -#else -#define STACK_REGISTER(coro) -#define STACK_DEREGISTER(coro) -#endif - -// Define outside -extern intptr_t g_stackYieldLimit; - -typedef struct CallbackBlock { - void* context; - CoroStartCallback* func; -} CallbackBlock; - -Coro* Coro_new(void) { - Coro* self = (Coro*)io_calloc(1, sizeof(Coro)); - if (self == NULL) { - errno = ENOMEM; - return NULL; - } - - self->requestedStackSize = CORO_DEFAULT_STACK_SIZE; - self->allocatedStackSize = 0; - -#ifdef USE_FIBERS - self->fiber = NULL; -#else - self->stack = NULL; -#endif - return self; -} - -int Coro_allocStackIfNeeded(Coro* self) { - if (self->stack && self->requestedStackSize < self->allocatedStackSize) { - io_free(self->stack); - self->stack = NULL; - self->requestedStackSize = 0; - } - - if (!self->stack) { - self->stack = (void*)io_calloc(1, self->requestedStackSize + 16); - if (self->stack == NULL) { - errno = ENOMEM; - return ENOMEM; - } - - self->allocatedStackSize = self->requestedStackSize; - // printf("Coro_%p allocating stack size %i\n", (void *)self, self->requestedStackSize); - STACK_REGISTER(self); - } - - return 0; -} - -void Coro_free(Coro* self) { -#ifdef USE_FIBERS - // If this coro has a fiber, delete it. - // Don't delete the main fiber. We don't want to commit suicide. - if (self->fiber && !self->isMain) { - DeleteFiber(self->fiber); - } -#else - STACK_DEREGISTER(self); -#endif - if (self->stack) { - io_free(self->stack); - } - - // printf("Coro_%p io_free\n", (void *)self); - - io_free(self); -} - -// stack - -void* Coro_stack(Coro* self) { - return self->stack; -} - -size_t Coro_stackSize(Coro* self) { - return self->requestedStackSize; -} - -void Coro_setStackSize_(Coro* self, size_t sizeInBytes) { - self->requestedStackSize = sizeInBytes; - // self->stack = (void *)io_realloc(self->stack, sizeInBytes); - // printf("Coro_%p io_reallocating stack size %i\n", (void *)self, sizeInBytes); -} - -size_t Coro_bytesLeftOnStack(Coro* self) { - unsigned char dummy; - ptrdiff_t p1 = (ptrdiff_t)(&dummy); - /*ptrdiff_t p2 = (ptrdiff_t)Coro_CurrentStackPointer(); - int stackMovesUp = p2 > p1;*/ - - ptrdiff_t start = ((ptrdiff_t)self->stack); - ptrdiff_t end = start + self->requestedStackSize; - - if (/*stackMovesUp*/ 0) { - return end - p1; - } else { - return p1 - start; - } -} - -int Coro_stackSpaceAlmostGone(Coro* self) { - return Coro_bytesLeftOnStack(self) < CORO_STACK_SIZE_MIN; -} - -void Coro_initializeMainCoro(Coro* self) { - self->isMain = 1; - - // So that Coro_bytesLeftOnStack etc will do something on the main thread, guess that there is 800KB of stack - // "left" when this function is called. - - // FIXME: The commented code below could be adapted to find the actual stack size using pthreads - self->requestedStackSize = 800 << 10; - self->stack = (char*)&self - self->requestedStackSize; - self->allocatedStackSize = 0; - g_stackYieldLimit = (intptr_t)self->stack + 65536; - /* // Get the pthread attributes - pthread_attr_t Attributes; - void *StackAddress; - size_t StackSize; - memset (&Attributes, 0, sizeof (Attributes)); - pthread_getattr_np (pthread_self(), &Attributes); - - // From the attributes, get the stack info - pthread_attr_getstack (&Attributes, &StackAddress, &StackSize); - - // Done with the attributes - pthread_attr_destroy (&Attributes); - - printf ("Stack top: %p\n", StackAddress); - printf ("Stack size: %u bytes\n", StackSize); - printf ("Stack bottom: %p\n", (uint8_t*)StackAddress + StackSize);*/ - -#ifdef USE_FIBERS - // We must convert the current thread into a fiber if it hasn't already been done. - if ((LPVOID)0x1e00 == GetCurrentFiber()) // value returned when not a fiber - { - // Make this thread a fiber and set its data field to the main coro's address - ConvertThreadToFiber(self); - } - // Make the main coro represent the current fiber - self->fiber = GetCurrentFiber(); -#endif -} - -int Coro_startCoro_(Coro* self, Coro* other, void* context, CoroStartCallback* callback) { - CallbackBlock sblock; - int result; - - CallbackBlock* block = &sblock; - // CallbackBlock *block = malloc(sizeof(CallbackBlock)); // memory leak - block->context = context; - block->func = callback; - - result = Coro_allocStackIfNeeded(other); - if (result) - return result; - - Coro_setup(other, block); - Coro_switchTo_(self, other); - - return 0; -} - -/* -int Coro_startCoro_(Coro *self, Coro *other, void *context, CoroStartCallback *callback) -{ - int result; - globalCallbackBlock.context = context; - globalCallbackBlock.func = callback; - result = Coro_allocStackIfNeeded(other); - if (result) - return result; - - Coro_setup(other, &globalCallbackBlock); - Coro_switchTo_(self, other); - return 0; -} -*/ - -#if defined(USE_UCONTEXT) && defined(__x86_64__) -void Coro_StartWithArg(unsigned int hiArg, unsigned int loArg) { - setProfilingEnabled(1); - CallbackBlock* block = (CallbackBlock*)(((long long)hiArg << 32) | (long long)loArg); - (block->func)(block->context); - criticalError(FDB_EXIT_ABORT, "SchedulerError", "returned from coro start function"); -} - -/* -void Coro_Start(void) -{ - CallbackBlock block = globalCallbackBlock; - unsigned int hiArg = (unsigned int)(((long long)&block) >> 32); - unsigned int loArg = (unsigned int)(((long long)&block) & 0xFFFFFFFF); - Coro_StartWithArg(hiArg, loArg); -} -*/ -#else - -static CallbackBlock globalCallbackBlock; - -void Coro_StartWithArg(CallbackBlock* block) { - setProfilingEnabled(1); - (block->func)(block->context); - criticalError(FDB_EXIT_ABORT, "SchedulerError", "returned from coro start function"); -} - -void Coro_Start(void) { - CallbackBlock block = globalCallbackBlock; - Coro_StartWithArg(&block); -} - -#endif - -// -------------------------------------------------------------------- - -void Coro_switchTo_(Coro* self, Coro* next) { - g_stackYieldLimit = (intptr_t)next->stack + 65536; -#if defined(__SYMBIAN32__) - ProcessUIEvent(); -#elif defined(USE_FIBERS) - SwitchToFiber(next->fiber); -#elif defined(USE_UCONTEXT) - setProfilingEnabled(0); - swapcontext(&self->env, &next->env); - setProfilingEnabled(1); -#elif defined(USE_SETJMP) - if (setjmp(self->env) == 0) { - longjmp(next->env, 1); - } -#endif -} - -// ---- setup ------------------------------------------ - -#if defined(USE_SETJMP) && defined(__x86_64__) - -void Coro_setup(Coro* self, void* arg) { - /* since ucontext seems to be broken on amg64 */ - - setjmp(self->env); - /* This is probably not nice in that it deals directly with - * something with __ in front of it. - * - * Anyhow, Coro.h makes the member env of a struct Coro a - * jmp_buf. A jmp_buf, as defined in the amd64 setjmp.h - * is an array of one struct that wraps the actual __jmp_buf type - * which is the array of longs (on a 64 bit machine) that - * the programmer below expected. This struct begins with - * the __jmp_buf array of longs, so I think it was supposed - * to work like he originally had it, but for some reason - * it didn't. I don't know why. - * - Bryce Schroeder, 16 December 2006 - * - * Explanation of `magic' numbers: 6 is the stack pointer - * (RSP, the 64 bit equivalent of ESP), 7 is the program counter. - * This information came from this file on my Gentoo linux - * amd64 computer: - * /usr/include/gento-multilib/amd64/bits/setjmp.h - * Which was ultimately included from setjmp.h in /usr/include. */ - self->env[0].__jmpbuf[6] = ((unsigned long)(Coro_stack(self))); - self->env[0].__jmpbuf[7] = ((long)Coro_Start); -} - -#elif defined(HAS_UCONTEXT_ON_PRE_SOLARIS_10) - -typedef void (*makecontext_func)(void); - -void Coro_setup(Coro* self, void* arg) { - ucontext_t* ucp = (ucontext_t*)&self->env; - - getcontext(ucp); - - ucp->uc_stack.ss_sp = Coro_stack(self) + Coro_stackSize(self) - 8; - ucp->uc_stack.ss_size = Coro_stackSize(self); - ucp->uc_stack.ss_flags = 0; - ucp->uc_link = NULL; - - makecontext(ucp, (makecontext_func)Coro_StartWithArg, 1, arg); -} - -#elif defined(USE_UCONTEXT) - -typedef void (*makecontext_func)(void); - -void Coro_setup(Coro* self, void* arg) { - ucontext_t* ucp = (ucontext_t*)&self->env; - - getcontext(ucp); - - ucp->uc_stack.ss_sp = Coro_stack(self); - ucp->uc_stack.ss_size = Coro_stackSize(self); -#if !defined(__APPLE__) - ucp->uc_stack.ss_flags = 0; - ucp->uc_link = NULL; -#endif - -#if defined(__x86_64__) - unsigned int hiArg = (unsigned int)((long long)arg >> 32); - unsigned int loArg = (unsigned int)((long long)arg & 0xFFFFFFFF); - makecontext(ucp, (makecontext_func)Coro_StartWithArg, 2, hiArg, loArg); -#else - makecontext(ucp, (makecontext_func)Coro_StartWithArg, 1, arg); -#endif -} - -#elif defined(USE_FIBERS) - -void Coro_setup(Coro* self, void* arg) { - // If this coro was recycled and already has a fiber, delete it. - // Don't delete the main fiber. We don't want to commit suicide. - - if (self->fiber && !self->isMain) { - DeleteFiber(self->fiber); - } - - self->fiber = CreateFiber(Coro_stackSize(self), (LPFIBER_START_ROUTINE)Coro_StartWithArg, (LPVOID)arg); - if (!self->fiber) - criticalError(FDB_EXIT_ABORT, "SchedulerError", "unable to create fiber"); -} - -#elif defined(__CYGWIN__) - -#define buf (self->env) - -static CallbackBlock globalCallbackBlock; - -void Coro_setup(Coro* self, void* arg) { - setjmp(buf); - buf[7] = (long)(Coro_stack(self) + Coro_stackSize(self) - 16); - buf[8] = (long)Coro_Start; - globalCallbackBlock.context = ((CallbackBlock*)arg)->context; - globalCallbackBlock.func = ((CallbackBlock*)arg)->func; -} - -#elif defined(__SYMBIAN32__) - -void Coro_setup(Coro* self, void* arg) { - /* - setjmp/longjmp is flakey under Symbian. - If the setjmp is done inside the call then a crash occurs. - Inlining it here solves the problem - */ - - setjmp(self->env); - self->env[0] = 0; - self->env[1] = 0; - self->env[2] = 0; - self->env[3] = (unsigned long)(Coro_stack(self)) + Coro_stackSize(self) - 64; - self->env[9] = (long)Coro_Start; - self->env[8] = self->env[3] + 32; -} - -#elif defined(_BSD_PPC_SETJMP_H_) - -#define buf (self->env) -#define setjmp _setjmp -#define longjmp _longjmp - -static CallbackBlock globalCallbackBlock; - -void Coro_setup(Coro* self, void* arg) { - size_t* sp = (size_t*)(((intptr_t)Coro_stack(self) + Coro_stackSize(self) - 64 + 15) & ~15); - - setjmp(buf); - - // printf("self = %p\n", self); - // printf("sp = %p\n", sp); - buf[0] = (long)sp; - buf[21] = (long)Coro_Start; - globalCallbackBlock.context = ((CallbackBlock*)arg)->context; - globalCallbackBlock.func = ((CallbackBlock*)arg)->func; - // sp[-4] = (size_t)self; // for G5 10.3 - // sp[-6] = (size_t)self; // for G4 10.4 - - // printf("self = %p\n", (void *)self); - // printf("sp = %p\n", sp); -} - -/* -void Coro_setup(Coro *self, void *arg) -{ - size_t *sp = (size_t *)(((intptr_t)Coro_stack(self) - + Coro_stackSize(self) - 64 + 15) & ~15); - - setjmp(buf); - - //printf("self = %p\n", self); - //printf("sp = %p\n", sp); - buf[0] = (long)sp; - buf[21] = (long)Coro_Start; - //sp[-4] = (size_t)self; // for G5 10.3 - //sp[-6] = (size_t)self; // for G4 10.4 - - //printf("self = %p\n", (void *)self); - //printf("sp = %p\n", sp); -} -*/ - -#elif defined(__DragonFly__) - -#define buf (self->env) - -void Coro_setup(Coro* self, void* arg) { - void* stack = Coro_stack(self); - size_t stacksize = Coro_stackSize(self); - void* func = (void*)Coro_Start; - - setjmp(buf); - - buf->_jb[2] = (long)(stack + stacksize); - buf->_jb[0] = (long)func; - return; -} - -#elif defined(__arm__) -// contributed by Peter van Hardenberg - -#define buf (self->env) - -void Coro_setup(Coro* self, void* arg) { - setjmp(buf); - buf[8] = (int)Coro_stack(self) + (int)Coro_stackSize(self) - 16; - buf[9] = (int)Coro_Start; -} - -#else - -#error "Coro.c Error: Coro_setup() function needs to be defined for this platform." - -#endif - -// old code - -/* - // APPLE coros are handled by PortableUContext now -#elif defined(_BSD_PPC_SETJMP_H_) - -#define buf (self->env) -#define setjmp _setjmp -#define longjmp _longjmp - - void Coro_setup(Coro *self, void *arg) - { - size_t *sp = (size_t *)(((intptr_t)Coro_stack(self) + Coro_stackSize(self) - 64 + 15) & ~15); - - setjmp(buf); - - //printf("self = %p\n", self); - //printf("sp = %p\n", sp); - buf[0] = (int)sp; - buf[21] = (int)Coro_Start; - //sp[-4] = (size_t)self; // for G5 10.3 - //sp[-6] = (size_t)self; // for G4 10.4 - - //printf("self = %p\n", (void *)self); - //printf("sp = %p\n", sp); - } - -#elif defined(_BSD_I386_SETJMP_H) - -#define buf (self->env) - - void Coro_setup(Coro *self, void *arg) - { - size_t *sp = (size_t *)((intptr_t)Coro_stack(self) + Coro_stackSize(self)); - - setjmp(buf); - - buf[9] = (int)(sp); // esp - buf[12] = (int)Coro_Start; // eip - //buf[8] = 0; // ebp - } - */ - -/* Solaris supports ucontext - so we don't need this stuff anymore - -void Coro_setup(Coro *self, void *arg) -{ - // this bit goes before the setjmp call - // Solaris 9 Sparc with GCC -#if defined(__SVR4) && defined (__sun) -#if defined(_JBLEN) && (_JBLEN == 12) && defined(__sparc) -#if defined(_LP64) || defined(_I32LPx) -#define JBTYPE long - JBTYPE x; -#else -#define JBTYPE int - JBTYPE x; - asm("ta 3"); // flush register window -#endif - -#define SUN_STACK_END_INDEX 1 -#define SUN_PROGRAM_COUNTER 2 -#define SUN_STACK_START_INDEX 3 - - // Solaris 9 i386 with GCC -#elif defined(_JBLEN) && (_JBLEN == 10) && defined(__i386) -#if defined(_LP64) || defined(_I32LPx) -#define JBTYPE long - JBTYPE x; -#else -#define JBTYPE int - JBTYPE x; -#endif -#define SUN_PROGRAM_COUNTER 5 -#define SUN_STACK_START_INDEX 3 -#define SUN_STACK_END_INDEX 4 -#endif -#endif - */ - -/* Irix supports ucontext - so we don't need this stuff anymore - -#elif defined(sgi) && defined(_IRIX4_SIGJBLEN) // Irix/SGI - -void Coro_setup(Coro *self, void *arg) -{ - setjmp(buf); - buf[JB_SP] = (__uint64_t)((char *)stack + stacksize - 8); - buf[JB_PC] = (__uint64_t)Coro_Start; -} -*/ - -/* Linux supports ucontext - so we don't need this stuff anymore - -#elif defined(linux) -// Various flavors of Linux. -#if defined(JB_GPR1) -// Linux/PPC -buf->__jmpbuf[JB_GPR1] = ((int) stack + stacksize - 64 + 15) & ~15; -buf->__jmpbuf[JB_LR] = (int) Coro_Start; -return; - -#elif defined(JB_RBX) -// Linux/Opteron -buf->__jmpbuf[JB_RSP] = (long int )stack + stacksize; -buf->__jmpbuf[JB_PC] = Coro_Start; -return; - -#elif defined(JB_SP) - -// Linux/x86 with glibc2 -buf->__jmpbuf[JB_SP] = (int)stack + stacksize; -buf->__jmpbuf[JB_PC] = (int)Coro_StartWithArg; -// Push the argument on the stack (stack grows downwards) -// note: stack is stacksize + 16 bytes long -((int *)stack)[stacksize/sizeof(int) + 1] = (int)self; -return; - -#elif defined(_I386_JMP_BUF_H) -// x86-linux with libc5 -buf->__sp = (int)stack + stacksize; -buf->__pc = Coro_Start; -return; - -#elif defined(__JMP_BUF_SP) -// arm-linux on the sharp zauras -buf->__jmpbuf[__JMP_BUF_SP] = (int)stack + stacksize; -buf->__jmpbuf[__JMP_BUF_SP+1] = (int)Coro_Start; -return; - -#else - -*/ - -/* Windows supports fibers - so we don't need this stuff anymore - -#elif defined(__MINGW32__) - -void Coro_setup(Coro *self, void *arg) -{ - setjmp(buf); - buf[4] = (int)((unsigned char *)stack + stacksize - 16); // esp - buf[5] = (int)Coro_Start; // eip -} - -#elif defined(_MSC_VER) - -void Coro_setup(Coro *self, void *arg) -{ - setjmp(buf); - // win32 visual c - // should this be the same as __MINGW32__? - buf[4] = (int)((unsigned char *)stack + stacksize - 16); // esp - buf[5] = (int)Coro_Start; // eip -} -*/ - -/* FreeBSD supports ucontext - so we don't need this stuff anymore - -#elif defined(__FreeBSD__) -// FreeBSD. -#if defined(_JBLEN) && (_JBLEN == 81) -// FreeBSD/Alpha -buf->_jb[2] = (long)Coro_Start; // sc_pc -buf->_jb[26+4] = (long)Coro_Start; // sc_regs[R_RA] -buf->_jb[27+4] = (long)Coro_Start; // sc_regs[R_T12] -buf->_jb[30+4] = (long)(stack + stacksize); // sc_regs[R_SP] -return; - -#elif defined(_JBLEN) -// FreeBSD on IA32 -buf->_jb[2] = (long)(stack + stacksize); -buf->_jb[0] = (long)Coro_Start; -return; - -#else -#error Unsupported platform -#endif -*/ - -/* NetBSD supports ucontext - so we don't need this stuff anymore - -#elif defined(__NetBSD__) - -void Coro_setup(Coro *self, void *arg) -{ - setjmp(buf); -#if defined(_JB_ATTRIBUTES) - // NetBSD i386 - buf[2] = (long)(stack + stacksize); - buf[0] = (long)Coro_Start; -#else -#error Unsupported platform -#endif -} -*/ - -/* Sun supports ucontext - so we don't need this stuff anymore - -// Solaris supports ucontext - so we don't need this stuff anymore - -void Coro_setup(Coro *self, void *arg) -{ - // this bit goes before the setjmp call - // Solaris 9 Sparc with GCC -#if defined(__SVR4) && defined (__sun) -#if defined(_JBLEN) && (_JBLEN == 12) && defined(__sparc) -#if defined(_LP64) || defined(_I32LPx) -#define JBTYPE long - JBTYPE x; -#else -#define JBTYPE int - JBTYPE x; - asm("ta 3"); // flush register window -#endif - -#define SUN_STACK_END_INDEX 1 -#define SUN_PROGRAM_COUNTER 2 -#define SUN_STACK_START_INDEX 3 - - // Solaris 9 i386 with GCC -#elif defined(_JBLEN) && (_JBLEN == 10) && defined(__i386) -#if defined(_LP64) || defined(_I32LPx) -#define JBTYPE long - JBTYPE x; -#else -#define JBTYPE int - JBTYPE x; -#endif -#define SUN_PROGRAM_COUNTER 5 -#define SUN_STACK_START_INDEX 3 -#define SUN_STACK_END_INDEX 4 -#endif -#endif - - -#elif defined(__SVR4) && defined(__sun) - // Solaris -#if defined(SUN_PROGRAM_COUNTER) - // SunOS 9 - buf[SUN_PROGRAM_COUNTER] = (JBTYPE)Coro_Start; - - x = (JBTYPE)stack; - while ((x % 8) != 0) x --; // align on an even boundary - buf[SUN_STACK_START_INDEX] = (JBTYPE)x; - x = (JBTYPE)((JBTYPE)stack-stacksize / 2 + 15); - while ((x % 8) != 0) x ++; // align on an even boundary - buf[SUN_STACK_END_INDEX] = (JBTYPE)x; - - */ diff --git a/fdbrpc/libcoroutine/Coro.h b/fdbrpc/libcoroutine/Coro.h deleted file mode 100644 index a2b36fcf60f..00000000000 --- a/fdbrpc/libcoroutine/Coro.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - */ - -#ifndef CORO_DEFINED -#define CORO_DEFINED 1 -#pragma once - -#ifndef WIN32 -#include "taskimpl.h" -#endif - -#if defined(__SYMBIAN32__) -#define CORO_STACK_SIZE 8192 -#define CORO_STACK_SIZE_MIN 1024 -#else -// #define CORO_DEFAULT_STACK_SIZE (65536/2) -// #define CORO_DEFAULT_STACK_SIZE (65536*4) - -// 128k needed on PPC due to parser -#define CORO_DEFAULT_STACK_SIZE (128 * 1024) -#define CORO_STACK_SIZE_MIN 8192 -#endif - -#if !defined(__MINGW32__) && defined(WIN32) && 0 -#if defined(BUILDING_CORO_DLL) || defined(BUILDING_IOVMALL_DLL) -#define CORO_API __declspec(dllexport) -#else -#define CORO_API __declspec(dllimport) -#endif - -#else -#define CORO_API -#endif - -/* -#if defined(__amd64__) && !defined(__x86_64__) - #define __x86_64__ 1 -#endif -*/ - -// Pick which coro implementation to use -// The make file can set -DUSE_FIBERS, -DUSE_UCONTEXT or -DUSE_SETJMP to force this choice. -#if !defined(USE_FIBERS) && !defined(USE_UCONTEXT) && !defined(USE_SETJMP) - -#if defined(WIN32) && defined(HAS_FIBERS) -#define USE_FIBERS -#elif defined(HAS_UCONTEXT) -// #elif defined(HAS_UCONTEXT) && !defined(__x86_64__) -#if !defined(USE_UCONTEXT) -#define USE_UCONTEXT -#endif -#else -#define USE_SETJMP -#endif - -#endif - -#if defined(USE_FIBERS) -#define CORO_IMPLEMENTATION "fibers" -#elif defined(USE_UCONTEXT) -#include -#define CORO_IMPLEMENTATION "ucontext" -#elif defined(USE_SETJMP) -#include -#define CORO_IMPLEMENTATION "setjmp" -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct Coro Coro; - -struct Coro { - size_t requestedStackSize; - size_t allocatedStackSize; - void* stack; - -#ifdef USE_VALGRIND - unsigned int valgrindStackId; -#endif - -#if defined(USE_FIBERS) - void* fiber; -#elif defined(USE_UCONTEXT) - ucontext_t env; -#elif defined(USE_SETJMP) - jmp_buf env; -#endif - - unsigned char isMain; -}; - -// Returns NULL if not enough memory was available to create the Coroutine -CORO_API Coro* Coro_new(void); - -CORO_API void Coro_free(Coro* self); - -// stack - -CORO_API void* Coro_stack(Coro* self); -CORO_API size_t Coro_stackSize(Coro* self); -CORO_API void Coro_setStackSize_(Coro* self, size_t sizeInBytes); -CORO_API size_t Coro_bytesLeftOnStack(Coro* self); -CORO_API int Coro_stackSpaceAlmostGone(Coro* self); - -CORO_API void Coro_initializeMainCoro(Coro* self); - -typedef void(CoroStartCallback)(void*); - -// Returns -1 if not enough memory is available to allocate a coroutine stack. Otherwise, returns 0 -CORO_API int Coro_startCoro_(Coro* self, Coro* other, void* context, CoroStartCallback* callback); - -CORO_API void Coro_switchTo_(Coro* self, Coro* next); -CORO_API void Coro_setup(Coro* self, void* arg); // private - -#ifdef __cplusplus -} -#endif -#endif diff --git a/fdbrpc/libcoroutine/amd64-ucontext.h b/fdbrpc/libcoroutine/amd64-ucontext.h deleted file mode 100644 index 444122d338b..00000000000 --- a/fdbrpc/libcoroutine/amd64-ucontext.h +++ /dev/null @@ -1,135 +0,0 @@ -#define setcontext(u) setmcontext(&(u)->uc_mcontext) -#define getcontext(u) getmcontext(&(u)->uc_mcontext) -typedef struct mcontext mcontext_t; -typedef struct ucontext ucontext_t; - -extern int swapcontext(ucontext_t*, const ucontext_t*); -extern void makecontext(ucontext_t*, void (*)(void), int, ...); -extern int getmcontext(mcontext_t*); -extern void setmcontext(const mcontext_t*); - -/*- - * Copyright (c) 1999 Marcel Moolenaar - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer - * in this position and unchanged. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD: src/sys/sys/ucontext.h,v 1.4 1999/10/11 20:33:17 luoqi Exp $ - */ - -/* #include */ - -/*- - * Copyright (c) 1999 Marcel Moolenaar - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer - * in this position and unchanged. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD: src/sys/i386/include/ucontext.h,v 1.4 1999/10/11 20:33:09 luoqi Exp $ - */ - -struct mcontext { - /* - * The first 20 fields must match the definition of - * sigcontext. So that we can support sigcontext - * and ucontext_t at the same time. - */ - long mc_onstack; /* XXX - sigcontext compat. */ - long mc_rdi; /* machine state (struct trapframe) */ - long mc_rsi; - long mc_rdx; - long mc_rcx; - long mc_r8; - long mc_r9; - long mc_rax; - long mc_rbx; - long mc_rbp; - long mc_r10; - long mc_r11; - long mc_r12; - long mc_r13; - long mc_r14; - long mc_r15; - long mc_trapno; - long mc_addr; - long mc_flags; - long mc_err; - long mc_rip; - long mc_cs; - long mc_rflags; - long mc_rsp; - long mc_ss; - - long mc_len; /* sizeof(mcontext_t) */ -#define _MC_FPFMT_NODEV 0x10000 /* device not present or configured */ -#define _MC_FPFMT_XMM 0x10002 - long mc_fpformat; -#define _MC_FPOWNED_NONE 0x20000 /* FP state not used */ -#define _MC_FPOWNED_FPU 0x20001 /* FP state came from FPU */ -#define _MC_FPOWNED_PCB 0x20002 /* FP state came from PCB */ - long mc_ownedfp; - /* - * See for the internals of mc_fpstate[]. - */ - long mc_fpstate[64]; - long mc_spare[8]; -}; - -struct ucontext { - /* - * Keep the order of the first two fields. Also, - * keep them the first two fields in the structure. - * This way we can have a union with struct - * sigcontext and ucontext_t. This allows us to - * support them both at the same time. - * note: the union is not defined, though. - */ - sigset_t uc_sigmask; - mcontext_t uc_mcontext; - - struct __ucontext* uc_link; - stack_t uc_stack; - int __spare__[8]; -}; diff --git a/fdbrpc/libcoroutine/asm.S b/fdbrpc/libcoroutine/asm.S deleted file mode 100644 index f6afa46ebf4..00000000000 --- a/fdbrpc/libcoroutine/asm.S +++ /dev/null @@ -1,260 +0,0 @@ -/* Copyright (c) 2005-2006 Russ Cox, MIT; see COPYRIGHT */ - -#if defined(__FreeBSD__) && defined(__i386__) && __FreeBSD__ < 5 -#define NEEDX86CONTEXT 1 -#define SET setmcontext -#define GET getmcontext -#endif - -#if defined(__OpenBSD__) && defined(__i386__) -#define NEEDX86CONTEXT 1 -#define SET setmcontext -#define GET getmcontext -#endif - -#if defined(__APPLE__) -#if defined(__i386__) -#define NEEDX86CONTEXT 1 -#define SET _setmcontext -#define GET _getmcontext -#elif defined(__x86_64__) -#define NEEDAMD64CONTEXT 1 -#define SET _setmcontext -#define GET _getmcontext -#else -#define NEEDPOWERCONTEXT 1 -#define SET __setmcontext -#define GET __getmcontext -#endif -#endif - -#if defined(__linux__) && defined(__arm__) -#define NEEDARMCONTEXT 1 -#define SET setmcontext -#define GET getmcontext -#endif - -#ifdef NEEDX86CONTEXT -.globl SET -SET: - movl 4(%esp), %eax - - movl 8(%eax), %fs - movl 12(%eax), %es - movl 16(%eax), %ds - movl 76(%eax), %ss - movl 20(%eax), %edi - movl 24(%eax), %esi - movl 28(%eax), %ebp - movl 36(%eax), %ebx - movl 40(%eax), %edx - movl 44(%eax), %ecx - - movl 72(%eax), %esp - pushl 60(%eax) /* new %eip */ - movl 48(%eax), %eax - ret - -.globl GET -GET: - movl 4(%esp), %eax - - movl %fs, 8(%eax) - movl %es, 12(%eax) - movl %ds, 16(%eax) - movl %ss, 76(%eax) - movl %edi, 20(%eax) - movl %esi, 24(%eax) - movl %ebp, 28(%eax) - movl %ebx, 36(%eax) - movl %edx, 40(%eax) - movl %ecx, 44(%eax) - - movl $1, 48(%eax) /* %eax */ - movl (%esp), %ecx /* %eip */ - movl %ecx, 60(%eax) - leal 4(%esp), %ecx /* %esp */ - movl %ecx, 72(%eax) - - movl 44(%eax), %ecx /* restore %ecx */ - movl $0, %eax - ret -#endif - -#ifdef NEEDAMD64CONTEXT -.globl SET -SET: - movq 16(%rdi), %rsi - movq 24(%rdi), %rdx - movq 32(%rdi), %rcx - movq 40(%rdi), %r8 - movq 48(%rdi), %r9 - movq 56(%rdi), %rax - movq 64(%rdi), %rbx - movq 72(%rdi), %rbp - movq 80(%rdi), %r10 - movq 88(%rdi), %r11 - movq 96(%rdi), %r12 - movq 104(%rdi), %r13 - movq 112(%rdi), %r14 - movq 120(%rdi), %r15 - movq 184(%rdi), %rsp - pushq 160(%rdi) /* new %eip */ - movq 8(%rdi), %rdi - ret - -.globl GET -GET: - movq %rdi, 8(%rdi) - movq %rsi, 16(%rdi) - movq %rdx, 24(%rdi) - movq %rcx, 32(%rdi) - movq %r8, 40(%rdi) - movq %r9, 48(%rdi) - movq $1, 56(%rdi) /* %rax */ - movq %rbx, 64(%rdi) - movq %rbp, 72(%rdi) - movq %r10, 80(%rdi) - movq %r11, 88(%rdi) - movq %r12, 96(%rdi) - movq %r13, 104(%rdi) - movq %r14, 112(%rdi) - movq %r15, 120(%rdi) - - movq (%rsp), %rcx /* %rip */ - movq %rcx, 160(%rdi) - leaq 8(%rsp), %rcx /* %rsp */ - movq %rcx, 184(%rdi) - - movq 32(%rdi), %rcx /* restore %rcx */ - movq $0, %rax - ret -#endif - -#ifdef NEEDPOWERCONTEXT -/* get FPR and VR use flags with sc 0x7FF3 */ -/* get vsave with mfspr reg, 256 */ - -.text -.align 2 - -.globl GET -GET: /* xxx: instruction scheduling */ - mflr r0 - mfcr r5 - mfctr r6 - mfxer r7 - stw r0, 0*4(r3) - stw r5, 1*4(r3) - stw r6, 2*4(r3) - stw r7, 3*4(r3) - - stw r1, 4*4(r3) - stw r2, 5*4(r3) - li r5, 1 /* return value for setmcontext */ - stw r5, 6*4(r3) - - stw r13, (0+7)*4(r3) /* callee-save GPRs */ - stw r14, (1+7)*4(r3) /* xxx: block move */ - stw r15, (2+7)*4(r3) - stw r16, (3+7)*4(r3) - stw r17, (4+7)*4(r3) - stw r18, (5+7)*4(r3) - stw r19, (6+7)*4(r3) - stw r20, (7+7)*4(r3) - stw r21, (8+7)*4(r3) - stw r22, (9+7)*4(r3) - stw r23, (10+7)*4(r3) - stw r24, (11+7)*4(r3) - stw r25, (12+7)*4(r3) - stw r26, (13+7)*4(r3) - stw r27, (14+7)*4(r3) - stw r28, (15+7)*4(r3) - stw r29, (16+7)*4(r3) - stw r30, (17+7)*4(r3) - stw r31, (18+7)*4(r3) - - li r3, 0 /* return */ - blr - -.globl SET -SET: - lwz r13, (0+7)*4(r3) /* callee-save GPRs */ - lwz r14, (1+7)*4(r3) /* xxx: block move */ - lwz r15, (2+7)*4(r3) - lwz r16, (3+7)*4(r3) - lwz r17, (4+7)*4(r3) - lwz r18, (5+7)*4(r3) - lwz r19, (6+7)*4(r3) - lwz r20, (7+7)*4(r3) - lwz r21, (8+7)*4(r3) - lwz r22, (9+7)*4(r3) - lwz r23, (10+7)*4(r3) - lwz r24, (11+7)*4(r3) - lwz r25, (12+7)*4(r3) - lwz r26, (13+7)*4(r3) - lwz r27, (14+7)*4(r3) - lwz r28, (15+7)*4(r3) - lwz r29, (16+7)*4(r3) - lwz r30, (17+7)*4(r3) - lwz r31, (18+7)*4(r3) - - lwz r1, 4*4(r3) - lwz r2, 5*4(r3) - - lwz r0, 0*4(r3) - mtlr r0 - lwz r0, 1*4(r3) - mtcr r0 /* mtcrf 0xFF, r0 */ - lwz r0, 2*4(r3) - mtctr r0 - lwz r0, 3*4(r3) - mtxer r0 - - lwz r3, 6*4(r3) - blr -#endif - -#ifdef NEEDARMCONTEXT -.globl GET -GET: - str r1, [r0,#4] - str r2, [r0,#8] - str r3, [r0,#12] - str r4, [r0,#16] - str r5, [r0,#20] - str r6, [r0,#24] - str r7, [r0,#28] - str r8, [r0,#32] - str r9, [r0,#36] - str r10, [r0,#40] - str r11, [r0,#44] - str r12, [r0,#48] - str r13, [r0,#52] - str r14, [r0,#56] - /* store 1 as r0-to-restore */ - mov r1, #1 - str r1, [r0] - /* return 0 */ - mov r0, #0 - mov pc, lr - -.globl SET -SET: - ldr r1, [r0,#4] - ldr r2, [r0,#8] - ldr r3, [r0,#12] - ldr r4, [r0,#16] - ldr r5, [r0,#20] - ldr r6, [r0,#24] - ldr r7, [r0,#28] - ldr r8, [r0,#32] - ldr r9, [r0,#36] - ldr r10, [r0,#40] - ldr r11, [r0,#44] - ldr r12, [r0,#48] - ldr r13, [r0,#52] - ldr r14, [r0,#56] - ldr r0, [r0] - mov pc, lr -#endif diff --git a/fdbrpc/libcoroutine/bsd_license.txt b/fdbrpc/libcoroutine/bsd_license.txt deleted file mode 100644 index 2427fecb8c3..00000000000 --- a/fdbrpc/libcoroutine/bsd_license.txt +++ /dev/null @@ -1,14 +0,0 @@ -(This is a BSD License) - -Copyright (c) 2002, 2003 Steve Dekorte -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - -¥ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. -¥ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. -¥ Neither the name of the author nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - diff --git a/fdbrpc/libcoroutine/context.c b/fdbrpc/libcoroutine/context.c deleted file mode 100644 index ad62f9caf88..00000000000 --- a/fdbrpc/libcoroutine/context.c +++ /dev/null @@ -1,105 +0,0 @@ -/* Copyright (c) 2005-2006 Russ Cox, MIT; see COPYRIGHT */ - -#include "taskimpl.h" - -#if defined(__APPLE__) -#if defined(__i386__) -#define NEEDX86MAKECONTEXT -#define NEEDSWAPCONTEXT -#elif defined(__x86_64__) -#define NEEDAMD64MAKECONTEXT -#define NEEDSWAPCONTEXT -#else -#define NEEDPOWERMAKECONTEXT -#define NEEDSWAPCONTEXT -#endif -#endif - -#if defined(__FreeBSD__) && defined(__i386__) && __FreeBSD__ < 5 -#define NEEDX86MAKECONTEXT -#define NEEDSWAPCONTEXT -#endif - -#if defined(__OpenBSD__) && defined(__i386__) -#define NEEDX86MAKECONTEXT -#define NEEDSWAPCONTEXT -#endif - -#if defined(__linux__) && defined(__arm__) -#define NEEDSWAPCONTEXT -#define NEEDARMMAKECONTEXT -#endif - -#ifdef NEEDPOWERMAKECONTEXT -void makecontext(ucontext_t* ucp, void (*func)(void), int argc, ...) { - ulong *sp, *tos; - va_list arg; - - tos = (ulong*)ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size / sizeof(ulong); - sp = tos - 16; - ucp->mc.pc = (long)func; - ucp->mc.sp = (long)sp; - va_start(arg, argc); - ucp->mc.r3 = va_arg(arg, long); - va_end(arg); -} -#endif - -#ifdef NEEDX86MAKECONTEXT -void makecontext(ucontext_t* ucp, void (*func)(void), int argc, ...) { - int* sp; - - sp = (int*)ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size / 4; - sp -= argc; - sp = (void*)((uintptr_t)sp - (uintptr_t)sp % 16); /* 16-align for OS X */ - memmove(sp, &argc + 1, argc * sizeof(int)); - - *--sp = 0; /* return address */ - ucp->uc_mcontext.mc_eip = (long)func; - ucp->uc_mcontext.mc_esp = (int)sp; -} -#endif - -#ifdef NEEDAMD64MAKECONTEXT -void makecontext(ucontext_t* ucp, void (*func)(void), int argc, ...) { - long* sp; - va_list va; - - memset(&ucp->uc_mcontext, 0, sizeof ucp->uc_mcontext); - if (argc != 2) - __builtin_trap(); - va_start(va, argc); - ucp->uc_mcontext.mc_rdi = va_arg(va, int); - ucp->uc_mcontext.mc_rsi = va_arg(va, int); - va_end(va); - sp = (long*)ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size / sizeof(long); - sp -= argc; - sp = (void*)((uintptr_t)sp - (uintptr_t)sp % 16); /* 16-align for OS X */ - *--sp = 0; /* return address */ - ucp->uc_mcontext.mc_rip = (long)func; - ucp->uc_mcontext.mc_rsp = (long)sp; -} -#endif - -#ifdef NEEDARMMAKECONTEXT -void makecontext(ucontext_t* uc, void (*fn)(void), int argc, ...) { - int i, *sp; - va_list arg; - - sp = (int*)uc->uc_stack.ss_sp + uc->uc_stack.ss_size / 4; - va_start(arg, argc); - for (i = 0; i < 4 && i < argc; i++) - uc->uc_mcontext.gregs[i] = va_arg(arg, uint); - va_end(arg); - uc->uc_mcontext.gregs[13] = (uint)sp; - uc->uc_mcontext.gregs[14] = (uint)fn; -} -#endif - -#ifdef NEEDSWAPCONTEXT -int swapcontext(ucontext_t* oucp, const ucontext_t* ucp) { - if (getcontext(oucp) == 0) - setcontext(ucp); - return 0; -} -#endif diff --git a/fdbrpc/libcoroutine/power-ucontext.h b/fdbrpc/libcoroutine/power-ucontext.h deleted file mode 100644 index 2fd67e8e87c..00000000000 --- a/fdbrpc/libcoroutine/power-ucontext.h +++ /dev/null @@ -1,34 +0,0 @@ -#define setcontext(u) _setmcontext(&(u)->mc) -#define getcontext(u) _getmcontext(&(u)->mc) -typedef struct mcontext mcontext_t; -typedef struct ucontext ucontext_t; -struct mcontext { - ulong pc; /* lr */ - ulong cr; /* mfcr */ - ulong ctr; /* mfcr */ - ulong xer; /* mfcr */ - ulong sp; /* callee saved: r1 */ - ulong toc; /* callee saved: r2 */ - ulong r3; /* first arg to function, return register: r3 */ - ulong gpr[19]; /* callee saved: r13-r31 */ - /* - // XXX: currently do not save vector registers or floating-point state - // ulong pad; - // uvlong fpr[18]; / * callee saved: f14-f31 * / - // ulong vr[4*12]; / * callee saved: v20-v31, 256-bits each * / - */ -}; - -struct ucontext { - struct { - void* ss_sp; - uint ss_size; - } uc_stack; - sigset_t uc_sigmask; - mcontext_t mc; -}; - -void makecontext(ucontext_t*, void (*)(void), int, ...); -int swapcontext(ucontext_t*, const ucontext_t*); -int _getmcontext(mcontext_t*); -void _setmcontext(const mcontext_t*); diff --git a/fdbrpc/libcoroutine/taskimpl.h b/fdbrpc/libcoroutine/taskimpl.h deleted file mode 100644 index dfe20f93efa..00000000000 --- a/fdbrpc/libcoroutine/taskimpl.h +++ /dev/null @@ -1,185 +0,0 @@ -#ifndef TASKIMPL_DEFINED -#define TASKIMPL_DEFINED 1 - -#include - -/* Copyright (c) 2005-2006 Russ Cox, MIT; see COPYRIGHT */ - -#if defined(__sun__) -#define __EXTENSIONS__ 1 /* SunOS */ -#if defined(__SunOS5_6__) || defined(__SunOS5_7__) || defined(__SunOS5_8__) -/* NOT USING #define __MAKECONTEXT_V2_SOURCE 1 / * SunOS */ -#else -#define __MAKECONTEXT_V2_SOURCE 1 -#endif -#endif - -// #define USE_UCONTEXT 1 - -#if defined(__OpenBSD__) -#undef USE_UCONTEXT -#define USE_UCONTEXT 0 -#endif - -#if defined(__APPLE__) -#include -#if defined(MAC_OS_X_VERSION_10_5) -#undef USE_UCONTEXT -#define USE_UCONTEXT 0 -#endif -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#if USE_UCONTEXT -#include -#endif -#include -#include -// #include "task.h" - -#define nil ((void*)0) -#define nelem(x) (sizeof(x) / sizeof((x)[0])) - -/* -#define ulong task_ulong -#define uint task_uint -#define uchar task_uchar -#define ushort task_ushort -#define uvlong task_uvlong -#define vlong task_vlong - -typedef unsigned long ulong; -typedef unsigned int uint; -typedef unsigned char uchar; -typedef unsigned short ushort; -typedef unsigned long long uvlong; -typedef long long vlong; - -#define print task_print -#define fprint task_fprint -#define snprint task_snprint -#define seprint task_seprint -#define vprint task_vprint -#define vfprint task_vfprint -#define vsnprint task_vsnprint -#define vseprint task_vseprint -#define strecpy task_strecpy - -int print(char*, ...); -int fprint(int, char*, ...); -char *snprint(char*, uint, char*, ...); -char *seprint(char*, char*, char*, ...); -int vprint(char*, va_list); -int vfprint(int, char*, va_list); -char *vsnprint(char*, uint, char*, va_list); -char *vseprint(char*, char*, char*, va_list); -char *strecpy(char*, char*, char*); -*/ - -#if defined(__FreeBSD__) && __FreeBSD__ < 5 -extern int getmcontext(mcontext_t*); -extern void setmcontext(const mcontext_t*); -#define setcontext(u) setmcontext(&(u)->uc_mcontext) -#define getcontext(u) getmcontext(&(u)->uc_mcontext) -extern int swapcontext(ucontext_t*, const ucontext_t*); -extern void makecontext(ucontext_t*, void (*)(), int, ...); -#endif - -#if defined(__APPLE__) -#define mcontext libthread_mcontext -#define mcontext_t libthread_mcontext_t -#define ucontext libthread_ucontext -#define ucontext_t libthread_ucontext_t -#if defined(__i386__) -#include "386-ucontext.h" -#elif defined(__x86_64__) -#include "amd64-ucontext.h" -#else -#include "power-ucontext.h" -#endif -#endif - -#if defined(__OpenBSD__) -#define mcontext libthread_mcontext -#define mcontext_t libthread_mcontext_t -#define ucontext libthread_ucontext -#define ucontext_t libthread_ucontext_t -#if defined __i386__ -#include "386-ucontext.h" -#else -#include "power-ucontext.h" -#endif -extern pid_t rfork_thread(int, void*, int (*)(void*), void*); -#endif - -#if 0 && defined(__sun__) -#define mcontext libthread_mcontext -#define mcontext_t libthread_mcontext_t -#define ucontext libthread_ucontext -#define ucontext_t libthread_ucontext_t -#include "sparc-ucontext.h" -#endif - -#if defined(__arm__) -int getmcontext(mcontext_t*); -void setmcontext(const mcontext_t*); -#define setcontext(u) setmcontext(&(u)->uc_mcontext) -#define getcontext(u) getmcontext(&(u)->uc_mcontext) -#endif - -/* -typedef struct Context Context; - -enum -{ - STACK = 8192 -}; - -struct Context -{ - ucontext_t uc; -}; - -struct Task -{ - char name[256]; // offset known to acid - char state[256]; - Task *next; - Task *prev; - Task *allnext; - Task *allprev; - Context context; - uvlong alarmtime; - uint id; - uchar *stk; - uint stksize; - int exiting; - int alltaskslot; - int system; - int ready; - void (*startfn)(void*); - void *startarg; - void *udata; -}; - -void taskready(Task*); -void taskswitch(void); - -void addtask(Tasklist*, Task*); -void deltask(Tasklist*, Task*); - -extern Task *taskrunning; -extern int taskcount; -*/ - -#endif diff --git a/fdbserver/CMakeLists.txt b/fdbserver/CMakeLists.txt index 3f353c2ef30..d050c51a876 100644 --- a/fdbserver/CMakeLists.txt +++ b/fdbserver/CMakeLists.txt @@ -1,12 +1,5 @@ fdb_find_sources(FDBSERVER_SRCS) -if(${COROUTINE_IMPL} STREQUAL libcoro) - list(APPEND FDBSERVER_SRCS coroimpl/CoroFlowCoro.actor.cpp) -else() - list(APPEND FDBSERVER_SRCS coroimpl/CoroFlow.actor.cpp) -endif() - - if(WITH_ROCKSDB) include(CompileRocksDB) # CompileRocksDB sets `lz4_LIBRARIES` to be the shared lib, we want to link @@ -20,6 +13,8 @@ endif() file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/workloads) +list(APPEND FDBSERVER_SRCS coroimpl/CoroFlow.actor.cpp) + add_flow_target(EXECUTABLE NAME fdbserver SRCS ${FDBSERVER_SRCS}) if (WITH_SWIFT) diff --git a/fdbserver/coroimpl/CoroFlow.actor.cpp b/fdbserver/coroimpl/CoroFlow.actor.cpp index f3fffa2f8ef..db7a887c7a5 100644 --- a/fdbserver/coroimpl/CoroFlow.actor.cpp +++ b/fdbserver/coroimpl/CoroFlow.actor.cpp @@ -19,16 +19,20 @@ */ #include "fdbserver/CoroFlow.h" -#include "flow/ActorCollection.h" -#include "flow/TDMetric.actor.h" -#include "fdbrpc/simulator.h" -#include "fdbrpc/SimulatorProcessInfo.h" + +#include + #include #include -#include + +#include "fdbrpc/simulator.h" +#include "fdbrpc/SimulatorProcessInfo.h" +#include "fdbrpc/SimulatorProcessInfo.h" +#include "flow/ActorCollection.h" #include "flow/flow.h" #include "flow/network.h" -#include "fdbrpc/SimulatorProcessInfo.h" +#include "flow/TDMetric.actor.h" + #include "flow/actorcompiler.h" // has to be last include using coro_t = boost::coroutines2::coroutine>; diff --git a/fdbserver/coroimpl/CoroFlowCoro.actor.cpp b/fdbserver/coroimpl/CoroFlowCoro.actor.cpp deleted file mode 100644 index 03e7e783ce2..00000000000 --- a/fdbserver/coroimpl/CoroFlowCoro.actor.cpp +++ /dev/null @@ -1,304 +0,0 @@ -/* - * CoroFlowCoro.actor.cpp - * - * This source file is part of the FoundationDB open source project - * - * Copyright 2013-2022 Apple Inc. and the FoundationDB project authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "fdbserver/CoroFlow.h" -#include "flow/ActorCollection.h" -#include "Coro.h" -#include "flow/TDMetric.actor.h" -#include "fdbrpc/simulator.h" -#include "fdbrpc/SimulatorProcessInfo.h" -#include "flow/actorcompiler.h" // has to be last include - -// Old libcoroutine based implementation. Used on Windows until CI has -// boost context installed - -Coro *current_coro = 0, *main_coro = 0; -Coro* swapCoro(Coro* n) { - Coro* t = current_coro; - current_coro = n; - return t; -} - -/*struct IThreadlike { -public: - virtual void start() = 0; // Call at most once! Causes run() to be called on the 'thread'. - virtual ~IThreadlike() {} // Pre: start hasn't been called, or run() has returned - virtual void unblock() = 0; // Pre: block() has been called by run(). Causes block() to return. - -protected: - virtual void block() = 0; // Call only from run(). Returns when unblock() is called elsewhere. - virtual void run() = 0; // To be overridden by client. Returning causes the thread to block until it is -destroyed. -};*/ - -struct Coroutine /*: IThreadlike*/ { - Coroutine() { - coro = Coro_new(); - if (coro == nullptr) - platform::outOfMemory(); - } - - ~Coroutine() { Coro_free(coro); } - - void start() { - int result = Coro_startCoro_(swapCoro(coro), coro, this, &entry); - if (result == ENOMEM) - platform::outOfMemory(); - } - - void unblock() { - // Coro_switchTo_( swapCoro(coro), coro ); - blocked.send(Void()); - } - -protected: - void block() { - // Coro_switchTo_( swapCoro(main_coro), main_coro ); - blocked = Promise(); - double before = now(); - CoroThreadPool::waitFor(blocked.getFuture()); - if (g_network->isSimulated() && g_simulator->getCurrentProcess()->rebooting) - TraceEvent("CoroUnblocked").detail("After", now() - before); - } - - virtual void run() = 0; - -private: - void wrapRun() { - run(); - Coro_switchTo_(swapCoro(main_coro), main_coro); - // block(); - } - - static void entry(void* _this) { ((Coroutine*)_this)->wrapRun(); } - - Coro* coro; - Promise blocked; -}; - -template -class WorkPool final : public IThreadPool, public ReferenceCounted> { - struct Worker; - - // Pool can survive the destruction of WorkPool while it waits for workers to terminate - struct Pool : ReferenceCounted { - Mutex queueLock; - Deque work; - std::vector idle, workers; - ActorCollection anyError, allStopped; - Future m_holdRefUntilStopped; - - Pool() : anyError(false), allStopped(true) { m_holdRefUntilStopped = holdRefUntilStopped(this); } - - ~Pool() { - for (int c = 0; c < workers.size(); c++) - delete workers[c]; - } - - ACTOR Future holdRefUntilStopped(Pool* p) { - p->addref(); - wait(p->allStopped.getResult()); - p->delref(); - return Void(); - } - }; - - struct Worker final : Threadlike { - Pool* pool; - IThreadPoolReceiver* userData; - bool stop; - ThreadReturnPromise stopped; - ThreadReturnPromise error; - - Worker(Pool* pool, IThreadPoolReceiver* userData) : pool(pool), userData(userData), stop(false) {} - - void run() override { - try { - if (!stop) - userData->init(); - - while (!stop) { - pool->queueLock.enter(); - if (pool->work.empty()) { - pool->idle.push_back(this); - pool->queueLock.leave(); - Threadlike::block(); - } else { - PThreadAction a = pool->work.front(); - pool->work.pop_front(); - pool->queueLock.leave(); - (*a)(userData); - if (IS_CORO) - CoroThreadPool::waitFor(yield()); - } - } - - TraceEvent("CoroStop").log(); - delete userData; - stopped.send(Void()); - return; - } catch (Error& e) { - TraceEvent("WorkPoolError").errorUnsuppressed(e); - error.sendError(e); - } catch (...) { - TraceEvent("WorkPoolError").log(); - error.sendError(unknown_error()); - } - - try { - delete userData; - } catch (...) { - TraceEvent(SevError, "WorkPoolErrorShutdownError").log(); - } - stopped.send(Void()); - } - }; - - Reference pool; - Future m_stopOnError; // must be last, because its cancellation calls stop()! - Error error; - - ACTOR Future stopOnError(WorkPool* w) { - try { - wait(w->getError()); - ASSERT(false); - } catch (Error& e) { - w->stop(e); - } - return Void(); - } - - void checkError() { - if (error.code() != invalid_error_code) { - ASSERT(error.code() != error_code_success); // Calling post or addThread after stop is an error - throw error; - } - } - -public: - WorkPool() : pool(new Pool) { m_stopOnError = stopOnError(this); } - - Future getError() const override { return pool->anyError.getResult(); } - void addThread(IThreadPoolReceiver* userData, const char*) override { - checkError(); - - auto w = new Worker(pool.getPtr(), userData); - pool->queueLock.enter(); - pool->workers.push_back(w); - pool->queueLock.leave(); - pool->anyError.add(w->error.getFuture()); - pool->allStopped.add(w->stopped.getFuture()); - startWorker(w); - } - ACTOR static void startWorker(Worker* w) { - // We want to make sure that coroutines are always started after Net2::run() is called, so the main coroutine is - // initialized. - wait(delay(0, g_network->getCurrentTask())); - w->start(); - } - void post(PThreadAction action) override { - checkError(); - - pool->queueLock.enter(); - pool->work.push_back(action); - if (!pool->idle.empty()) { - Worker* c = pool->idle.back(); - pool->idle.pop_back(); - pool->queueLock.leave(); - c->unblock(); - } else - pool->queueLock.leave(); - } - Future stop(Error const& e) override { - if (error.code() == invalid_error_code) { - error = e; - } - - pool->queueLock.enter(); - TraceEvent("WorkPool_Stop") - .errorUnsuppressed(e) - .detail("Workers", pool->workers.size()) - .detail("Idle", pool->idle.size()) - .detail("Work", pool->work.size()); - - for (uint32_t i = 0; i < pool->work.size(); i++) - pool->work[i]->cancel(); // What if cancel() does something to this? - pool->work.clear(); - for (int i = 0; i < pool->workers.size(); i++) - pool->workers[i]->stop = true; - - std::vector idle; - std::swap(idle, pool->idle); - pool->queueLock.leave(); - - for (int i = 0; i < idle.size(); i++) - idle[i]->unblock(); - - pool->allStopped.add(Void()); - - return pool->allStopped.getResult(); - } - bool isCoro() const override { return IS_CORO; } - void addref() override { ReferenceCounted::addref(); } - void delref() override { ReferenceCounted::delref(); } -}; - -typedef WorkPool CoroPool; - -ACTOR void coroSwitcher(Future what, TaskPriority taskID, Coro* coro) { - try { - // state double t = now(); - wait(what); - // if (g_network->isSimulated() && g_simulator->getCurrentProcess()->rebooting && now()!=t) - // TraceEvent("NonzeroWaitDuringReboot").detail("TaskID", taskID).detail("Elapsed", now()-t).backtrace("Flow"); - } catch (Error&) { - } - wait(delay(0, taskID)); - Coro_switchTo_(swapCoro(coro), coro); -} - -void CoroThreadPool::waitFor(Future what) { - ASSERT(current_coro != main_coro); - if (what.isReady()) - return; - // double t = now(); - coroSwitcher(what, g_network->getCurrentTask(), current_coro); - Coro_switchTo_(swapCoro(main_coro), main_coro); - // if (g_network->isSimulated() && g_simulator->getCurrentProcess()->rebooting && now()!=t) - // TraceEvent("NonzeroWaitDuringReboot").detail("TaskID", currentTaskID).detail("Elapsed", - // now()-t).backtrace("Coro"); - ASSERT(what.isReady()); -} - -// Right After INet2::run -void CoroThreadPool::init() { - if (!current_coro) { - current_coro = main_coro = Coro_new(); - if (main_coro == nullptr) - platform::outOfMemory(); - - Coro_initializeMainCoro(main_coro); - // printf("Main thread: %d bytes stack presumed available\n", Coro_bytesLeftOnStack(current_coro)); - } -} - -Reference CoroThreadPool::createThreadPool() { - return Reference(new CoroPool); -} diff --git a/fdbserver/fdbserver.actor.cpp b/fdbserver/fdbserver.actor.cpp index 13023973b90..69a579a722e 100644 --- a/fdbserver/fdbserver.actor.cpp +++ b/fdbserver/fdbserver.actor.cpp @@ -2045,6 +2045,7 @@ int main(int argc, char* argv[]) { // Initialize the thread pool CoroThreadPool::init(); + // Ordinarily, this is done when the network is run. However, network thread should be set before TraceEvents // are logged. This thread will eventually run the network, so call it now. TraceEvent::setNetworkThread(); diff --git a/fdbserver/include/fdbserver/IKeyValueStore.h b/fdbserver/include/fdbserver/IKeyValueStore.h index 2fa33163862..2dd24209ea7 100644 --- a/fdbserver/include/fdbserver/IKeyValueStore.h +++ b/fdbserver/include/fdbserver/IKeyValueStore.h @@ -20,10 +20,11 @@ #ifndef FDBSERVER_IKEYVALUESTORE_H #define FDBSERVER_IKEYVALUESTORE_H -#include "fdbclient/GetEncryptCipherKeys.h" + #pragma once #include "fdbclient/FDBTypes.h" +#include "fdbclient/GetEncryptCipherKeys.h" #include "fdbclient/IKeyValueStore.actor.h" #include "flow/BooleanParam.h" diff --git a/fdbserver/include/fdbserver/VFSAsync.h b/fdbserver/include/fdbserver/VFSAsync.h index 2a0ac8caebe..1c45f76ecc8 100644 --- a/fdbserver/include/fdbserver/VFSAsync.h +++ b/fdbserver/include/fdbserver/VFSAsync.h @@ -19,6 +19,7 @@ */ #include "sqlite3.h" + #include #include #include "flow/IAsyncFile.h"