diff --git a/.gitignore b/.gitignore index e356cf9..381caa8 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,8 @@ # generated docs doc/doxygen/* -/.vscode \ No newline at end of file +# IDE & Editors +/.vscode + +# generated files +/include/libcopp/utils/config/build_feature.h diff --git a/include/include.macro.cmake b/include/include.macro.cmake index bfd019f..517e7c7 100644 --- a/include/include.macro.cmake +++ b/include/include.macro.cmake @@ -26,13 +26,15 @@ if (LIBCOPP_ENABLE_SEGMENTED_STACKS) EchoWithColor(COLOR YELLOW "-- set LIBCOPP_ENABLE_SEGMENTED_STACKS but gcc 4.7.0 and upper support segmented stacks") unset(LIBCOPP_ENABLE_SEGMENTED_STACKS) else() + EchoWithColor(COLOR GREEN "-- Enable segmented stacks") add_definitions(-fsplit-stack) + set(COPP_MACRO_USE_SEGMENTED_STACKS 1) endif() endif() configure_file( - "${PROJECT_ROOT_INC_DIR}/libcopp/utils/features.h.in" - "${PROJECT_ROOT_INC_DIR}/libcopp/utils/features.h" + "${PROJECT_ROOT_INC_DIR}/libcopp/utils/config/build_feature.h.in" + "${PROJECT_ROOT_INC_DIR}/libcopp/utils/config/build_feature.h" @ONLY -) \ No newline at end of file +) diff --git a/include/libcopp/utils/config/build_feature.h.in b/include/libcopp/utils/config/build_feature.h.in new file mode 100644 index 0000000..fefee2a --- /dev/null +++ b/include/libcopp/utils/config/build_feature.h.in @@ -0,0 +1,10 @@ +// cmake template file + +#ifndef _COPP_UTILS_CONFIG_BUILD_FEATURES_H_ +#define _COPP_UTILS_CONFIG_BUILD_FEATURES_H_ + +# pragma once + +#cmakedefine COPP_MACRO_USE_SEGMENTED_STACKS @COPP_MACRO_USE_SEGMENTED_STACKS@ + +#endif diff --git a/include/libcopp/utils/config/compiler_features.h b/include/libcopp/utils/config/compiler_features.h index db0966c..073314a 100644 --- a/include/libcopp/utils/config/compiler_features.h +++ b/include/libcopp/utils/config/compiler_features.h @@ -29,7 +29,6 @@ # define UTIL_CONFIG_COMPILER_IS_MSVC 0 # define UTIL_CONFIG_COMPILER_IS_ADSP 0 # define UTIL_CONFIG_COMPILER_IS_IAR 0 -# define UTIL_CONFIG_COMPILER_IS_ARMCC 0 # define UTIL_CONFIG_COMPILER_IS_MIPSpro 0 #if defined(__COMO__) @@ -128,10 +127,6 @@ # undef UTIL_CONFIG_COMPILER_IS_IAR # define UTIL_CONFIG_COMPILER_IS_IAR 1 -#elif defined(__ARMCC_VERSION) -# undef UTIL_CONFIG_COMPILER_IS_ARMCC -# define UTIL_CONFIG_COMPILER_IS_ARMCC 1 - #elif defined(_SGI_COMPILER_VERSION) || defined(_COMPILER_VERSION) # undef UTIL_CONFIG_COMPILER_IS_MIPSpro # define UTIL_CONFIG_COMPILER_IS_MIPSpro 1 diff --git a/include/libcopp/utils/features.h b/include/libcopp/utils/features.h index fb5c8e3..6b23f01 100644 --- a/include/libcopp/utils/features.h +++ b/include/libcopp/utils/features.h @@ -1,3 +1,5 @@ +// cmake template file + #ifndef _COPP_UTILS_FEATURES_H_ #define _COPP_UTILS_FEATURES_H_ @@ -9,6 +11,7 @@ #include // ================ build options ================ +#include // ---------------- build options ---------------- // ================ select compiler ================ diff --git a/include/libcopp/utils/features.h.in b/include/libcopp/utils/features.h.in deleted file mode 100644 index 2c0c413..0000000 --- a/include/libcopp/utils/features.h.in +++ /dev/null @@ -1,126 +0,0 @@ -// cmake template file - -#ifndef _COPP_UTILS_FEATURES_H_ -#define _COPP_UTILS_FEATURES_H_ - - -#if defined(_MSC_VER) && (_MSC_VER >= 1020) -# pragma once -#endif - -#include - -// ================ build options ================ -#cmakedefine LIBCOPP_ENABLE_SEGMENTED_STACKS -// ---------------- build options ---------------- - -// ================ select compiler ================ -#if defined(__GCCXML__) - #define COPP_MACRO_COMPILER_GCCXML 1 -#elif defined (__clang__) - #define COPP_MACRO_COMPILER_CLANG 1 -#elif defined(_MSC_VER) - #define COPP_MACRO_COMPILER_MSVC 1 -#elif defined(__INTEL_COMPILER) || defined(__ICL) || defined(__ICC) || defined(__ECC) - #define COPP_MACRO_COMPILER_INTELC 1 -#elif defined(__GNUC__) - #define COPP_MACRO_COMPILER_GCC 1 -#elif defined(__BORLANDC__) - #define COPP_MACRO_COMPILER_BORLANDC 1 -#endif -// ---------------- select compiler ---------------- - -// ================ select platform ================ -#if (defined(linux) || defined(__linux) || defined(__linux__) || defined(__GNU__) || defined(__GLIBC__)) && !defined(_CRAYC) - #define COPP_MACRO_PLATFORM_LINUX -#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) - #define COPP_MACRO_PLATFORM_BSD -#elif defined(sun) || defined(__sun) - #define COPP_MACRO_PLATFORM_SOLARIS -#elif defined(__sgi) - #define COPP_MACRO_PLATFORM_SGI -#elif defined(__hpux) - #define COPP_MACRO_PLATFORM_HPUNIX -#elif defined(__CYGWIN__) - #define COPP_MACRO_PLATFORM_CYGWIN -#elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32) - #define COPP_MACRO_PLATFORM_WIN32 -#else - #if defined(unix) || defined(__unix) || defined(_XOPEN_SOURCE) || defined(_POSIX_SOURCE) - #define COPP_MACRO_PLATFORM_UNIX - #endif -# endif -// ---------------- select platform ---------------- - -// ================ c extern ================ -#if !defined(__BEGIN_DECLS) && !defined(__END_DECLS) - #if defined(__cplusplus) - #define __BEGIN_DECLS extern "C" { - #define __END_DECLS } - #else - #define __BEGIN_DECLS - #define __END_DECLS - #endif -#endif - -#if !defined(__THROW) -#define __THROW -#endif -// ---------------- c extern ---------------- -#if defined(UTIL_CONFIG_NOEXCEPT) - #define COPP_MACRO_NOEXCEPT UTIL_CONFIG_NOEXCEPT -#else - #define COPP_MACRO_NOEXCEPT -#endif - -// ================ compiler abi headers ================ -#if defined(COPP_MACRO_COMPILER_MSVC) - #define COPP_HAS_ABI_HEADERS 1 - #define COPP_ABI_PREFIX "libcopp/utils/abi/msvc_prefix.hpp" - #define COPP_ABI_SUFFIX "libcopp/utils/abi/msvc_suffix.hpp" -#elif defined COPP_MACRO_COMPILER_BORLANDC - #define COPP_HAS_ABI_HEADERS 1 - #define COPP_ABI_PREFIX "libcopp/utils/abi/borland_prefix.hpp" - #define COPP_ABI_SUFFIX "libcopp/utils/abi/borland_suffix.hpp" -#endif -// ---------------- compiler abi headers ---------------- - - -// ================ function flags ================ - - -#if defined(COPP_MACRO_USE_SEGMENTED_STACKS) -# if ! ( (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ > 3 && __GNUC_MINOR__ > 6))) || \ - (defined(__clang__) && __clang_major__ > 2 && __clang_minor__ > 3) ) -# error "compiler does not support segmented_stack stacks" -# endif -# define COPP_MACRO_SEGMENTED_STACK_NUMBER 10 -#endif - -#ifndef COPP_MACRO_CPP_STD - #if defined(__cplusplus) && __cplusplus >= 201103L - #define COPP_MACRO_CPP_STD 201103L - #define COPP_MACRO_ENABLE_SMART_PTR 1 - #else - #define COPP_MACRO_CPP_STD 199711L - #endif -#endif - - -#if defined(UTIL_CONFIG_COMPILER_CXX_VARIADIC_TEMPLATES) && UTIL_CONFIG_COMPILER_CXX_VARIADIC_TEMPLATES -#define COPP_MACRO_ENABLE_VARIADIC_TEMPLATE 1 -#endif - -#include -#if defined(STD_DECLTYPE) - #define COPP_MACRO_TYPEOF(...) STD_DECLTYPE(__VA_ARGS__) -#endif - -#if defined(_POSIX_MT_) || defined(_MSC_VER) - #define COPP_MACRO_ENABLE_MULTI_THREAD -#endif -// ---------------- function flags ---------------- - -#include "errno.h" - -#endif diff --git a/src/libcopp/coroutine/coroutine_context_base.cpp b/src/libcopp/coroutine/coroutine_context_base.cpp index ff487a9..914142d 100644 --- a/src/libcopp/coroutine/coroutine_context_base.cpp +++ b/src/libcopp/coroutine/coroutine_context_base.cpp @@ -197,14 +197,14 @@ namespace copp { // can not use any more stack now #ifdef COPP_MACRO_USE_SEGMENTED_STACKS - assert(&from_stack != &to_stack); + assert(&from_sctx != &to_sctx); __splitstack_getcontext(from_sctx.segments_ctx); __splitstack_setcontext(to_sctx.segments_ctx); // ROOT->A: jump_transfer.from_co == NULL, jump_transfer.to_co == A, from_sctx == A.caller_stack_, skip backup segments // A->B.start(): jump_transfer.from_co == A, jump_transfer.to_co == B, from_sctx == B.caller_stack_, backup segments // B.yield()->A: jump_transfer.from_co == B, jump_transfer.to_co == NULL, from_sctx == B.callee_stack_, skip backup segments - if (NULL != jump_transfer.from_co && (&from_stack) != &jump_transfer.from_co->callee_stack_) { + if (NULL != jump_transfer.from_co && (&from_sctx) != &jump_transfer.from_co->callee_stack_) { memcpy(&jump_transfer.from_co->callee_stack_.segments_ctx, &from_sctx.segments_ctx, sizeof(from_sctx.segments_ctx)); } #endif diff --git a/src/libcopp/stack/allocator/stack_allocator_memory.cpp b/src/libcopp/stack/allocator/stack_allocator_memory.cpp index 0ccfcf0..d66d9de 100644 --- a/src/libcopp/stack/allocator/stack_allocator_memory.cpp +++ b/src/libcopp/stack/allocator/stack_allocator_memory.cpp @@ -50,7 +50,7 @@ namespace copp { ctx.sp = static_cast(start_ptr_) + ctx.size; // stack down #if defined(COPP_MACRO_USE_VALGRIND) - ctx.valgrind_stack_id = VALGRIND_STACK_REGISTER(ctx.sp, start_ptr); + ctx.valgrind_stack_id = VALGRIND_STACK_REGISTER(ctx.sp, start_ptr_); #endif } diff --git a/src/libcopp/stack/stack.src.filter.cmake b/src/libcopp/stack/stack.src.filter.cmake index 51e8b34..29834e7 100644 --- a/src/libcopp/stack/stack.src.filter.cmake +++ b/src/libcopp/stack/stack.src.filter.cmake @@ -28,10 +28,9 @@ if(NOT WIN32 AND UNIX) add_compiler_define(COPP_MACRO_SYS_POSIX=1) endif() -if(COPP_MACRO_USE_SEGMENTED_STACKS_GCC) +if(LIBCOPP_ENABLE_SEGMENTED_STACKS) EchoWithColor(COLOR GREEN "-- gcc ${CMAKE_CXX_COMPILER_VERSION} found in unix like system.") - EchoWithColor(COLOR GREEN "-- stack allocator: enable segment allocator, add -DCOPP_MACRO_USE_SEGMENTED_STACKS") - add_definitions(-DCOPP_MACRO_USE_SEGMENTED_STACKS) + EchoWithColor(COLOR GREEN "-- stack allocator: enable segment allocator, add -fsplit-stack to all program use this library") list(APPEND COPP_SRC_LIST "${PROJECT_LIBCOPP_STACK_ALLOC_SRC_DIR}/stack_allocator_split_segment.cpp") endif() diff --git a/src/libcopp/stack/stack_context.cpp b/src/libcopp/stack/stack_context.cpp index ed0aa62..7337412 100644 --- a/src/libcopp/stack/stack_context.cpp +++ b/src/libcopp/stack/stack_context.cpp @@ -9,7 +9,7 @@ namespace copp { ,segments_ctx() #endif #ifdef COPP_MACRO_USE_VALGRIND - ,valgrind_stack_id(0); + ,valgrind_stack_id(0) #endif { }