├── CMakeLists.txt ├── README ├── benchmarks ├── CMakeLists.txt ├── context.cpp.inc ├── context_loop.cpp.inc ├── coroutine.cpp ├── deretta-coroutine │ ├── boost │ │ └── coroutine │ │ │ ├── coroutine.hpp │ │ │ ├── detail │ │ │ ├── arg_max.hpp │ │ │ ├── argument_packer.hpp │ │ │ ├── argument_unpacker.hpp │ │ │ ├── call_impl.hpp │ │ │ ├── context_base.hpp │ │ │ ├── context_linux.hpp │ │ │ ├── context_posix.hpp │ │ │ ├── context_windows.hpp │ │ │ ├── coroutine_accessor.hpp │ │ │ ├── coroutine_impl.hpp │ │ │ ├── coroutine_traits.hpp │ │ │ ├── default_context_impl.hpp │ │ │ ├── fix_result.hpp │ │ │ ├── future_impl.hpp │ │ │ ├── has_swap.hpp │ │ │ ├── index.hpp │ │ │ ├── is_callable.hpp │ │ │ ├── make_tuple_traits.hpp │ │ │ ├── noreturn.hpp │ │ │ ├── posix_utility.hpp │ │ │ ├── self.hpp │ │ │ ├── signal.hpp │ │ │ ├── signature.hpp │ │ │ ├── swap_context.hpp │ │ │ ├── wait_impl.hpp │ │ │ └── yield_result_type.hpp │ │ │ ├── exception.hpp │ │ │ ├── future.hpp │ │ │ ├── generator.hpp │ │ │ ├── move.hpp │ │ │ ├── shared_coroutine.hpp │ │ │ ├── tags │ │ │ └── tuple_traits.hpp │ └── libs │ │ └── coroutine │ │ ├── benchmark │ │ ├── Jamfile │ │ ├── call_overhead.cpp │ │ ├── make.sh │ │ └── out_of_line.cpp │ │ ├── build │ │ └── Jamfile.v2 │ │ ├── doc │ │ ├── Jamfile.v2 │ │ └── coroutine.qbk │ │ ├── example │ │ ├── Jamfile.v2 │ │ ├── banana.cpp │ │ ├── complex_matcher.cpp │ │ ├── consumer_producer_a.cpp │ │ ├── consumer_producer_b.cpp │ │ ├── consumer_producer_c.cpp │ │ ├── coroutine_fsm.cpp │ │ ├── coroutine_fsm_regexp.cpp │ │ ├── factorial.cpp │ │ ├── matcher.cpp │ │ ├── prisonerdilemma.cpp │ │ ├── samefringe.cpp │ │ ├── samefringe2.cpp │ │ ├── scheduler.cpp │ │ ├── scheduler_wait.cpp │ │ ├── switch_fsm.cpp │ │ ├── token_passing.cpp │ │ └── token_passing_baseline.cpp │ │ ├── src │ │ ├── coroutine.cpp │ │ ├── swapcontext.cpp │ │ └── swapcontext.s │ │ └── test │ │ ├── Jamfile.v2 │ │ ├── test_any.cpp │ │ ├── test_call.cpp │ │ ├── test_create.cpp │ │ ├── test_generator.cpp │ │ ├── test_invoke.cpp │ │ ├── test_meta.cpp │ │ ├── test_move.cpp │ │ ├── test_non_default_constructible.cpp │ │ ├── test_optional.cpp │ │ ├── test_reference.cpp │ │ ├── test_yield.cpp │ │ ├── test_yield_to.cpp │ │ └── test_yield_to2.cpp ├── include │ ├── benchmark.hpp │ └── benchmark │ │ ├── clock.hpp │ │ ├── details │ │ └── posix.hpp │ │ └── timer.hpp ├── oslinuxContext.cpp ├── oslinuxContextLoop.cpp ├── posixContext.cpp ├── posixContextLoop.cpp ├── stack.cpp ├── stats.py └── virtcall.cpp ├── include └── coroutine │ ├── best_context.hpp │ ├── builder.hpp │ ├── context.hpp │ ├── coroutine.hpp │ ├── impl │ ├── context_linux.hpp │ ├── context_linux_x86_32.hpp │ ├── context_linux_x86_64.hpp │ ├── context_posix.hpp │ ├── stack_dynamic.hpp │ └── stack_static.hpp │ ├── stack.hpp │ └── yielder.hpp └── tests ├── CMakeLists.txt ├── context ├── CMakeLists.txt ├── context.cpp.inc ├── oslinuxABIcheck.cpp ├── oslinuxContext.cpp └── posixContext.cpp ├── coroutine ├── CMakeLists.txt ├── builder.cpp ├── coroutine.cpp ├── exception.cpp └── yielder.cpp ├── include └── test.hpp └── stack ├── CMakeLists.txt └── stack.cpp /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # CMakeLists.txt 3 | # Copyright © 2010 François-Xavier 'Bombela' Bourlet 4 | # 5 | # 6 | 7 | cmake_minimum_required(VERSION 2.6) 8 | 9 | project(zia CXX) 10 | 11 | ############################################################################### 12 | # BOOST CONFIGURATION 13 | ############################################################################### 14 | 15 | set(Boost_USE_STATIC_LIBS OFF) 16 | set(Boost_USE_MULTITHREADED ON) 17 | set(BOOST_INCLUDEDIR "/usr/local/include") 18 | set(Boost_ADDITIONAL_VERSIONS 1.47 1.46 1.44 1.43 1.42 1.41 1.40 1.39) 19 | add_definitions(-DBOOST_ALL_NO_LIB) 20 | 21 | ############################################################################### 22 | # COMPILER FLAGS 23 | ############################################################################### 24 | 25 | if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_COMPILER_IS_GNUCXX) 26 | set(PROFILING false CACHE BOOL "Use profilling") 27 | if (PROFILING) 28 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg") 29 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg") 30 | endif() 31 | 32 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-stack-protector") 33 | 34 | set(EXTRADEBUG false CACHE BOOL "Force extra debug info") 35 | 36 | set(NATIVECODE false CACHE BOOL "Generate native code") 37 | if (NATIVECODE) 38 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") 39 | endif() 40 | 41 | set(NOELIDECTOR false CACHE BOOL "Disable elide contructors optimization") 42 | if (NOELIDECTOR) 43 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-elide-constructors") 44 | endif() 45 | endif() 46 | 47 | if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") 48 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") 49 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") 50 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") 51 | 52 | if (EXTRADEBUG) 53 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3") 54 | endif() 55 | 56 | set(OMIT_FRAME_POINTER true CACHE BOOL "Omit frame pointer") 57 | if (OMIT_FRAME_POINTER) 58 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fomit-frame-pointer") 59 | endif() 60 | 61 | # ugly temparary hack 62 | include_directories( 63 | "/usr/include/x86_64-linux-gnu/" 64 | "/usr/include/i386-linux-gnu/" 65 | ) 66 | endif() 67 | 68 | if (CMAKE_COMPILER_IS_GNUCXX) 69 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") 70 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") 71 | 72 | if (EXTRADEBUG) 73 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -D_GLIBCXX_DEBUG") 74 | endif() 75 | 76 | include(CheckCXXCompilerFlag OPTIONAL RESULT_VARIABLE CMAKE_CHECK_CXX_FLAGS) 77 | if (CMAKE_CHECK_CXX_FLAGS) 78 | CHECK_CXX_COMPILER_FLAG(-flto GCC_WITH_LTO) 79 | if (GCC_WITH_LTO) 80 | set(LTO true CACHE BOOL "Use GCC Link Time Optimisation.") 81 | endif(GCC_WITH_LTO) 82 | CHECK_CXX_COMPILER_FLAG(-fwhole-program GCC_WITH_WP) 83 | if (GCC_WITH_WP) 84 | set(LTO_WP false CACHE BOOL 85 | "Use GCC Whole Program Link Time Optimisation.") 86 | endif(GCC_WITH_WP) 87 | endif(CMAKE_CHECK_CXX_FLAGS) 88 | 89 | if (LTO) 90 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto") 91 | set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} -flto") 92 | endif() 93 | 94 | if (LTO_WP) 95 | set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -fwhole-program") 96 | set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} 97 | -fwhole-program") 98 | endif() 99 | endif(CMAKE_COMPILER_IS_GNUCXX) 100 | 101 | ############################################################################### 102 | # COROUTINE CONFIGURATION 103 | ############################################################################### 104 | include_directories(${CMAKE_SOURCE_DIR}/include) 105 | 106 | set(LINUX_8664_2SWAPSITE true CACHE BOOL 107 | "Linux x86_64: swapContext copy pasted for help CPU prediction") 108 | if (NOT LINUX_8664_2SWAPSITE) 109 | add_definitions(-DNO_CORO_LINUX_8664_2SWAPSITE) 110 | endif() 111 | 112 | set(LINUX_8632_2SWAPSITE true CACHE BOOL 113 | "Linux x86_32: swapContext copy pasted for help CPU prediction") 114 | if (NOT LINUX_8632_2SWAPSITE) 115 | add_definitions(-DNO_CORO_LINUX_8632_2SWAPSITE) 116 | endif() 117 | 118 | ############################################################################### 119 | # SUBDIRS 120 | ############################################################################### 121 | 122 | enable_testing() 123 | add_subdirectory(tests) 124 | add_subdirectory(benchmarks) 125 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Need cmake and boost to build. 2 | 3 | configure: 4 | mkdir build 5 | cd build 6 | cmake -DCMAKE_BUILD_TYPE=Release .. 7 | 8 | build: 9 | make 10 | 11 | run test: 12 | make test 13 | 14 | run benchmarks: 15 | make bench 16 | 17 | show nice benchmarks stats (need python and plotlib for python): 18 | make stat 19 | -------------------------------------------------------------------------------- /benchmarks/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # CMakeLists.txt 3 | # Copyright © 2010 François-Xavier 'Bombela' Bourlet 4 | # 5 | # 6 | 7 | find_package(Boost 1.38 REQUIRED system) 8 | include_directories(${Boost_INCLUDE_DIRS}) 9 | link_libraries(${Boost_LIBRARIES}) 10 | 11 | add_custom_target(bench) 12 | 13 | add_custom_target(cleanbench 14 | COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_CURRENT_BINARY_DIR}/bench.log 15 | VERBATIM 16 | ) 17 | 18 | add_custom_target(stat 19 | ${CMAKE_CURRENT_SOURCE_DIR}/stats.py ${CMAKE_CURRENT_BINARY_DIR}/bench.log 20 | ) 21 | 22 | macro(coroutine_add_bench src) 23 | get_filename_component(name ${src} NAME_WE) 24 | set(name "bench_${name}") 25 | add_executable(${name} ${src}) 26 | set(runname "${name}.run") 27 | add_custom_target(${runname} 28 | echo "Benchmarking ${name}..." 29 | COMMAND ${name} 30 | VERBATIM 31 | ) 32 | add_dependencies(bench ${runname}) 33 | endmacro() 34 | 35 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) 36 | 37 | set(BENCH_SRCS 38 | virtcall.cpp 39 | stack.cpp 40 | posixContext.cpp 41 | posixContextLoop.cpp 42 | oslinuxContext.cpp 43 | oslinuxContextLoop.cpp 44 | coroutine.cpp 45 | ) 46 | 47 | foreach(f ${BENCH_SRCS}) 48 | coroutine_add_bench(${f}) 49 | endforeach() 50 | -------------------------------------------------------------------------------- /benchmarks/context.cpp.inc: -------------------------------------------------------------------------------- 1 | /* vim: ft=cpp 2 | * posixContext.cpp 3 | * Copyright © 2010 François-Xavier 'Bombela' Bourlet 4 | * 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | #ifndef BENCH_TYPE 11 | 12 | #define BENCH_NAME(n) BENCH_CAT(n, BENCH_CAT(BENCH_TYPE, BENCH_CAT(_, BENCH_ARCH))) 13 | 14 | static const size_t stack_size = 2 * 1024 * 1024; 15 | 16 | #define BENCH_TYPE _static 17 | #define STACK stack::static_ 18 | #include "context.cpp.inc" 19 | #undef STACK 20 | #undef BENCH_TYPE 21 | 22 | #define BENCH_TYPE _dynamic 23 | #define STACK stack::dynamic 24 | #include "context.cpp.inc" 25 | #undef STACK 26 | #undef BENCH_TYPE 27 | 28 | #else 29 | 30 | #include 31 | 32 | using namespace coroutine; 33 | 34 | namespace BENCH_TYPE { 35 | 36 | void function(void*) { } 37 | 38 | BENCH(BENCH_NAME(createContext), 23, BENCH_CAT(createStack, BENCH_TYPE)) 39 | { 40 | typedef stack::stack stack_t; 41 | typedef context::context< 42 | context::resolve_alias::type 43 | , stack_t> context_t; 44 | 45 | UNUSED context_t context(&function, 0); 46 | } 47 | 48 | BENCH(BENCH_NAME(runContext), 23, BENCH_NAME(createContext)) 49 | { 50 | typedef stack::stack stack_t; 51 | typedef context::context< 52 | context::resolve_alias::type 53 | , stack_t> context_t; 54 | 55 | UNUSED context_t context(&function, 0); 56 | context.enter(); 57 | } 58 | 59 | } // namespace 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /benchmarks/context_loop.cpp.inc: -------------------------------------------------------------------------------- 1 | /* vim: ft=cpp 2 | * posixContext.cpp 3 | * Copyright © 2010 François-Xavier 'Bombela' Bourlet 4 | * 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | #ifndef BENCH_TYPE 11 | 12 | #define BENCH_NAME(n) BENCH_CAT(n, BENCH_CAT(BENCH_TYPE, BENCH_CAT(_, BENCH_ARCH))) 13 | 14 | static const size_t stack_size = 2 * 1024 * 1024; 15 | 16 | #define BENCH_TYPE _static 17 | #define STACK stack::static_ 18 | #include "context_loop.cpp.inc" 19 | #undef STACK 20 | #undef BENCH_TYPE 21 | 22 | #define BENCH_TYPE _dynamic 23 | #define STACK stack::dynamic 24 | #include "context_loop.cpp.inc" 25 | #undef STACK 26 | #undef BENCH_TYPE 27 | 28 | #else 29 | 30 | #include 31 | 32 | using namespace coroutine; 33 | 34 | namespace BENCH_TYPE { 35 | 36 | void function() { } 37 | 38 | struct LoopTester 39 | { 40 | static const long int LOOP_SIZE = 1 << 14; 41 | 42 | typedef stack::stack stack_t; 43 | typedef context::context< 44 | context::resolve_alias::type 45 | , stack_t> context_t; 46 | 47 | context_t* context; 48 | void setContext(context_t* c) { context = c; } 49 | 50 | void operator()() 51 | { 52 | for (int i = 0; i < LOOP_SIZE; ++i) { 53 | //printf("c %i\n",i); 54 | context->leave(); 55 | } 56 | } 57 | 58 | static void dotest(void* self) 59 | { 60 | (*(LoopTester*)self)(); 61 | } 62 | }; 63 | 64 | #ifdef BENCH_ARCH_POSIX 65 | # define RUN_CONTEXT_LOOP_CNT 10 66 | #else 67 | # define RUN_CONTEXT_LOOP_CNT 14 68 | #endif 69 | 70 | __attribute__((noinline)) void dothebench() 71 | { 72 | LoopTester functor; 73 | 74 | LoopTester::context_t context(&LoopTester::dotest, &functor); 75 | functor.setContext(&context); 76 | 77 | for (int i = 0; i < LoopTester::LOOP_SIZE; ++i) { 78 | //printf("m %i\n",i); 79 | context.enter(); 80 | } 81 | } 82 | 83 | BENCH(BENCH_NAME(runContextLoop), RUN_CONTEXT_LOOP_CNT) 84 | { 85 | dothebench(); 86 | } 87 | 88 | } // namespace 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /benchmarks/coroutine.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * stack.cpp 3 | * Copyright © 2010 François-Xavier 'Bombela' Bourlet 4 | * 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | using namespace coroutine; 14 | 15 | const long int LOOP_SIZE = 1L << 27; 16 | 17 | void empty_coro(yielder yield) { 18 | for (long int i = 0; i < LOOP_SIZE; ++i) 19 | yield(); 20 | abort(); 21 | } 22 | 23 | __attribute__((noinline)) void dothebench() { 24 | auto c = corof(empty_coro); 25 | for (long long int i = 0; i < LOOP_SIZE; ++i) 26 | c(); 27 | } 28 | 29 | BENCH(coroutine, 3) 30 | { 31 | dothebench(); 32 | } 33 | 34 | 35 | __attribute__((noinline)) void dothebench2() { 36 | auto c = corof(empty_coro); 37 | for (long long int i = 0; i < LOOP_SIZE; ++i) 38 | asm("nop"); 39 | } 40 | 41 | BENCH(simpleloop, 3) 42 | { 43 | dothebench2(); 44 | } 45 | 46 | BENCH_MAIN(fullbench) 47 | -------------------------------------------------------------------------------- /benchmarks/deretta-coroutine/boost/coroutine/detail/arg_max.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006, Giovanni P. Deretta 2 | // 3 | // This code may be used under either of the following two licences: 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. OF SUCH DAMAGE. 22 | // 23 | // Or: 24 | // 25 | // Distributed under the Boost Software License, Version 1.0. 26 | // (See accompanying file LICENSE_1_0.txt or copy at 27 | // http://www.boost.org/LICENSE_1_0.txt) 28 | 29 | #ifndef BOOST_COROUTINE_DETAIL_ARG_MAX_HPP_20060728 30 | # define BOOST_COROUTINE_DETAIL_ARG_MAX_HPP_20060728 31 | # ifndef BOOST_COROUTINE_ARG_MAX 32 | # define BOOST_COROUTINE_ARG_MAX 10 33 | # endif 34 | #endif 35 | -------------------------------------------------------------------------------- /benchmarks/deretta-coroutine/boost/coroutine/detail/argument_packer.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006, Giovanni P. Deretta 2 | // 3 | // This code may be used under either of the following two licences: 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. OF SUCH DAMAGE. 22 | // 23 | // Or: 24 | // 25 | // Distributed under the Boost Software License, Version 1.0. 26 | // (See accompanying file LICENSE_1_0.txt or copy at 27 | // http://www.boost.org/LICENSE_1_0.txt) 28 | 29 | #ifndef BOOST_COROUTINE_ARGUMENT_PACKER_HPP_20060601 30 | #define BOOST_COROUTINE_ARGUMENT_PACKER_HPP_20060601 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | namespace boost { namespace coroutines { namespace detail { 37 | #define BOOST_COROUTINE_DETAIL_TEMPLATE_PARAMETERS(n) \ 38 | template \ 39 | /**/ 40 | 41 | #define BOOST_COROUTINE_ARGUMENT_PACKER(z, n, parm_tuple) \ 42 | BOOST_PP_IF(n, \ 43 | BOOST_COROUTINE_DETAIL_TEMPLATE_PARAMETERS , \ 44 | BOOST_PP_TUPLE_EAT(1) )(n) \ 45 | BOOST_PP_TUPLE_ELEM(3, 0, parm_tuple) \ 46 | (BOOST_PP_ENUM_BINARY_PARAMS(n, T, arg)) { \ 47 | typedef BOOST_PP_TUPLE_ELEM(3, 2, parm_tuple) parm_type; \ 48 | return BOOST_PP_TUPLE_ELEM(3, 1, parm_tuple) \ 49 | (parm_type \ 50 | (BOOST_PP_ENUM_PARAMS(n, arg))); \ 51 | } \ 52 | /**/ 53 | 54 | 55 | #define BOOST_COROUTINE_ARGUMENT_PACKER_EX(z, n, parm_tuple) \ 56 | template \ 59 | BOOST_PP_TUPLE_ELEM(3, 0, parm_tuple) \ 60 | (Arg arg \ 61 | BOOST_PP_COMMA_IF(n) \ 62 | BOOST_PP_ENUM_BINARY_PARAMS(n, T, arg)) { \ 63 | typedef BOOST_PP_TUPLE_ELEM(3, 2, parm_tuple) parm_type; \ 64 | return BOOST_PP_TUPLE_ELEM(3, 1, parm_tuple)( arg, parm_type \ 65 | (BOOST_PP_ENUM_PARAMS(n, arg))); \ 66 | } \ 67 | /**/ 68 | 69 | } } } 70 | #endif 71 | -------------------------------------------------------------------------------- /benchmarks/deretta-coroutine/boost/coroutine/detail/call_impl.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006, Giovanni P. Deretta 2 | // 3 | // This code may be used under either of the following two licences: 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. OF SUCH DAMAGE. 22 | // 23 | // Or: 24 | // 25 | // Distributed under the Boost Software License, Version 1.0. 26 | // (See accompanying file LICENSE_1_0.txt or copy at 27 | // http://www.boost.org/LICENSE_1_0.txt) 28 | 29 | #ifndef BOOST_COROUTINE_DETAIL_CALL_IMPL_HPP_20060728 30 | #define BOOST_COROUTINE_DETAIL_CALL_IMPL_HPP_20060728 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | namespace boost { namespace coroutines { namespace detail { 41 | 42 | #define BOOST_COROUTINE_tuple_param_n(z, n, tuple)\ 43 | BOOST_DEDUCED_TYPENAME \ 44 | boost::tuples::element::type \ 45 | BOOST_PP_CAT(arg, n) \ 46 | /**/ 47 | 48 | template 49 | class callback { 50 | public: 51 | 52 | typedef void result_type; 53 | 54 | callback(Future& future) : 55 | m_future_pimpl(wait_gateway::get_impl(future)) { 56 | m_future_pimpl->mark_pending(); 57 | } 58 | 59 | typedef BOOST_DEDUCED_TYPENAME 60 | Future::tuple_type tuple_type; 61 | 62 | typedef BOOST_DEDUCED_TYPENAME 63 | Future::tuple_traits_type tuple_traits_type; 64 | 65 | /* 66 | * By default a callback is one shot only. 67 | * By calling this method you can revive a 68 | * callback for another shot. 69 | * You must guaranee that the future 70 | * is still alive. 71 | */ 72 | void revive() { 73 | m_future_pimpl->mark_pending(); 74 | } 75 | 76 | #define BOOST_COROUTINE_gen_argn_type(z, n, unused) \ 77 | typedef BOOST_DEDUCED_TYPENAME \ 78 | tuple_traits_type:: \ 79 | template at::type \ 80 | BOOST_PP_CAT(BOOST_PP_CAT(arg, n), _type); \ 81 | /**/ 82 | 83 | BOOST_PP_REPEAT(BOOST_COROUTINE_ARG_MAX, 84 | BOOST_COROUTINE_gen_argn_type, 85 | ~); 86 | 87 | #define BOOST_COROUTINE_param_with_default(z, n, type_prefix) \ 88 | BOOST_DEDUCED_TYPENAME call_traits \ 89 | \ 90 | ::param_type \ 91 | BOOST_PP_CAT(arg, n) = \ 92 | BOOST_PP_CAT(BOOST_PP_CAT(type_prefix, n), _type)() \ 93 | /**/ 94 | 95 | void operator() 96 | (BOOST_PP_ENUM 97 | (BOOST_COROUTINE_ARG_MAX, 98 | BOOST_COROUTINE_param_with_default, 99 | arg)) { 100 | m_future_pimpl->assign(tuple_type 101 | (BOOST_PP_ENUM_PARAMS 102 | (BOOST_COROUTINE_ARG_MAX, arg))); 103 | } 104 | 105 | private: 106 | BOOST_DEDUCED_TYPENAME 107 | Future::impl_pointer 108 | m_future_pimpl; 109 | }; 110 | 111 | #undef BOOST_COROUTINE_gen_future_assigner 112 | #undef BOOST_COROUTINE_tuple_param_n 113 | 114 | template 115 | Future call_impl(Functor fun, const CoroutineSelf& coro_self) { 116 | Future future(coro_self); 117 | fun(callback(future)); 118 | return future; 119 | } 120 | 121 | } } } 122 | 123 | #endif 124 | -------------------------------------------------------------------------------- /benchmarks/deretta-coroutine/boost/coroutine/detail/coroutine_accessor.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006, Giovanni P. Deretta 2 | // 3 | // This code may be used under either of the following two licences: 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. OF SUCH DAMAGE. 22 | // 23 | // Or: 24 | // 25 | // Distributed under the Boost Software License, Version 1.0. 26 | // (See accompanying file LICENSE_1_0.txt or copy at 27 | // http://www.boost.org/LICENSE_1_0.txt) 28 | 29 | #ifndef BOOST_COROUTINE_DETAIL_COROUTINE_ACCESSOR_HPP_20060709 30 | #define BOOST_COROUTINE_DETAIL_COROUTINE_ACCESSOR_HPP_20060709 31 | #include 32 | namespace boost { namespace coroutines { namespace detail { 33 | 34 | /* 35 | * This is a private interface used for coroutine 36 | * implementation. 37 | */ 38 | struct init_from_impl_tag{}; 39 | struct coroutine_accessor { 40 | 41 | // Initialize coroutine from implementation type. 42 | // used by the in_place_assing in place factory. 43 | template 44 | static 45 | void construct(Ctx * src, void * address) { 46 | new (address) Coroutine(src, init_from_impl_tag()); 47 | } 48 | 49 | template 50 | static 51 | void acquire(Coroutine& x) { 52 | x.acquire(); 53 | } 54 | 55 | template 56 | static 57 | void release(Coroutine& x) { 58 | x.release(); 59 | } 60 | 61 | template 62 | struct in_place_assign : boost::in_place_factory_base { 63 | 64 | in_place_assign(Ctx * ctx) : 65 | m_ctx(ctx) {} 66 | 67 | template 68 | void apply(void * memory) const { 69 | construct(m_ctx, memory); 70 | } 71 | Ctx * m_ctx; 72 | }; 73 | 74 | template 75 | static 76 | in_place_assign 77 | in_place(Ctx * ctx) { 78 | return in_place_assign(ctx); 79 | } 80 | 81 | template 82 | static 83 | typename Coroutine::impl_ptr 84 | get_impl(Coroutine& x) { 85 | return x.get_impl(); 86 | } 87 | 88 | template 89 | static 90 | typename Coroutine::impl_type * 91 | pilfer_impl(Coroutine& x) { 92 | return x.pilfer_impl(); 93 | } 94 | 95 | template 96 | static 97 | std::size_t 98 | count(const Coroutine& x) { 99 | return x.count(); 100 | } 101 | }; 102 | } } } 103 | #endif 104 | -------------------------------------------------------------------------------- /benchmarks/deretta-coroutine/boost/coroutine/detail/coroutine_traits.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006, Giovanni P. Deretta 2 | // 3 | // This code may be used under either of the following two licences: 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. OF SUCH DAMAGE. 22 | // 23 | // Or: 24 | // 25 | // Distributed under the Boost Software License, Version 1.0. 26 | // (See accompanying file LICENSE_1_0.txt or copy at 27 | // http://www.boost.org/LICENSE_1_0.txt) 28 | 29 | #ifndef BOOST_COROUTINE_DETAIL_COROUTINE_TRAITS_HPP_20060613 30 | #define BOOST_COROUTINE_DETAIL_COROUTINE_TRAITS_HPP_20060613 31 | #include 32 | #include 33 | #include 34 | 35 | namespace boost { namespace coroutines { namespace detail { 36 | 37 | template 38 | struct as_tuple { 39 | typedef typename T::as_tuple type; 40 | }; 41 | 42 | // This trait class is used to compute 43 | // all nested typedefs of coroutines given 44 | // a signature in the form 'result_type(parm1, ... parmn)'. 45 | template 46 | struct coroutine_traits { 47 | private: 48 | 49 | typedef BOOST_DEDUCED_TYPENAME boost::function_traits::result_type 50 | signature_result_type; 51 | public: 52 | typedef BOOST_DEDUCED_TYPENAME 53 | boost::mpl::eval_if, 54 | as_tuple, 55 | boost::mpl::identity > 56 | ::type result_type; 57 | 58 | typedef BOOST_DEDUCED_TYPENAME 59 | boost::mpl::eval_if, 60 | boost::mpl::identity, 61 | boost::mpl::if_ 62 | , 63 | tuple_traits<>, 64 | tuple_traits > > 65 | ::type result_slot_traits; 66 | 67 | typedef BOOST_DEDUCED_TYPENAME result_slot_traits 68 | ::as_tuple result_slot_type; 69 | 70 | typedef BOOST_DEDUCED_TYPENAME detail::make_tuple_traits 71 | ::type > 72 | ::type arg_slot_traits; 73 | 74 | typedef BOOST_DEDUCED_TYPENAME arg_slot_traits 75 | ::as_tuple arg_slot_type; 76 | 77 | typedef BOOST_DEDUCED_TYPENAME arg_slot_traits 78 | ::as_result yield_result_type; 79 | 80 | }; 81 | } } } 82 | #endif 83 | -------------------------------------------------------------------------------- /benchmarks/deretta-coroutine/boost/coroutine/detail/fix_result.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006, Giovanni P. Deretta 2 | // 3 | // This code may be used under either of the following two licences: 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. OF SUCH DAMAGE. 22 | // 23 | // Or: 24 | // 25 | // Distributed under the Boost Software License, Version 1.0. 26 | // (See accompanying file LICENSE_1_0.txt or copy at 27 | // http://www.boost.org/LICENSE_1_0.txt) 28 | 29 | #ifndef BOOST_COROUTINE_DETAIL_FIX_RESULT_HPP_20060709 30 | #define BOOST_COROUTINE_DETAIL_FIX_RESULT_HPP_20060709 31 | #include 32 | namespace boost { namespace coroutines { namespace detail { 33 | template 34 | inline 35 | void 36 | fix_result(const typename Traits::as_tuple&, 37 | typename 38 | boost::enable_if_c::type * = 0){} 39 | 40 | 41 | template 42 | inline 43 | typename Traits::template at<0>::type 44 | fix_result(const typename Traits::as_tuple& x, 45 | typename 46 | boost::enable_if_c::type * = 0){ 47 | using boost::get; 48 | return get<0>(x); 49 | } 50 | 51 | 52 | template 53 | inline 54 | typename Traits::as_tuple 55 | fix_result(const typename Traits::as_tuple& x, 56 | typename 57 | boost::enable_if_c<(Traits::length > 1)>::type* =0){ 58 | return x; 59 | } 60 | } } } 61 | #endif 62 | -------------------------------------------------------------------------------- /benchmarks/deretta-coroutine/boost/coroutine/detail/future_impl.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006, Giovanni P. Deretta 2 | // 3 | // This code may be used under either of the following two licences: 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. OF SUCH DAMAGE. 22 | // 23 | // Or: 24 | // 25 | // Distributed under the Boost Software License, Version 1.0. 26 | // (See accompanying file LICENSE_1_0.txt or copy at 27 | // http://www.boost.org/LICENSE_1_0.txt) 28 | 29 | #ifndef BOOST_COROUTINE_DETAIL_FUTURE_IMPL_HPP_20060809 30 | #define BOOST_COROUTINE_DETAIL_FUTURE_IMPL_HPP_20060809 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | namespace boost { namespace coroutines { namespace detail { 39 | 40 | 41 | template 42 | class future_impl : boost::noncopyable { 43 | public: 44 | typedef ValueType value_type; 45 | typedef 46 | context_base * 47 | context_weak_pointer; 48 | 49 | typedef 50 | BOOST_DEDUCED_TYPENAME 51 | context_base::pointer 52 | context_pointer; 53 | 54 | typedef boost::optional pointer; 55 | 56 | template 57 | future_impl(CoroutineSelf& self) : 58 | m_coro_impl_weak(coroutine_accessor::get_impl(self)), 59 | m_coro_impl(0), 60 | m_waited(false) 61 | {} 62 | 63 | value_type& 64 | value() { 65 | return *m_optional; 66 | } 67 | 68 | value_type const& 69 | value() const{ 70 | return *m_optional; 71 | } 72 | 73 | pointer& 74 | get() { 75 | return m_optional; 76 | } 77 | 78 | pointer const& 79 | get() const{ 80 | return m_optional; 81 | } 82 | 83 | bool pending() { 84 | return 0 != m_coro_impl.get(); 85 | } 86 | 87 | template 88 | void assign(const T& val) { 89 | BOOST_ASSERT(pending()); 90 | context_pointer p = m_coro_impl; 91 | m_coro_impl = 0; 92 | m_optional = val; 93 | p->count_down(); 94 | if(waited() && p->signal()) 95 | p->wake_up(); 96 | } 97 | 98 | void mark_pending() { 99 | m_coro_impl = m_coro_impl_weak; 100 | m_coro_impl ->count_up(); 101 | } 102 | 103 | void mark_wait(bool how) { 104 | m_waited = how; 105 | } 106 | 107 | bool waited() const { 108 | return m_waited; 109 | } 110 | 111 | context_pointer context() { 112 | BOOST_ASSERT(pending()); 113 | return m_coro_impl; 114 | } 115 | 116 | void wait(int n) { 117 | m_coro_impl_weak->wait(n); 118 | } 119 | 120 | void wait() { 121 | if(!pending()) return; 122 | mark_wait(true); 123 | try { 124 | m_coro_impl->wait(1); 125 | BOOST_ASSERT(!pending()); 126 | } catch (...) { 127 | mark_wait(false); 128 | throw; 129 | } 130 | mark_wait(false); 131 | } 132 | 133 | private: 134 | context_weak_pointer m_coro_impl_weak; 135 | context_pointer m_coro_impl; 136 | bool m_waited; 137 | boost::optional m_optional; 138 | }; 139 | } } } 140 | #endif 141 | -------------------------------------------------------------------------------- /benchmarks/deretta-coroutine/boost/coroutine/detail/has_swap.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006, Giovanni P. Deretta 2 | // 3 | // This code may be used under either of the following two licences: 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. OF SUCH DAMAGE. 22 | // 23 | // Or: 24 | // 25 | // Distributed under the Boost Software License, Version 1.0. 26 | // (See accompanying file LICENSE_1_0.txt or copy at 27 | // http://www.boost.org/LICENSE_1_0.txt) 28 | 29 | 30 | // Copyright David Abrahams 2004. Distributed under the Boost 31 | // Software License, Version 1.0. (See accompanying 32 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 33 | // 34 | // Slightly modified for inclusion on coroutines/detail library. 35 | #ifndef BOOST_COROUTINE_DETAIL_HAS_SWAP_HPP_20060709 36 | #define BOOST_COROUTINE_DETAIL_HAS_SWAP_HPP_20060709 37 | 38 | #include 39 | #include 40 | 41 | namespace boost { namespace coroutines { 42 | 43 | 44 | namespace has_swap_ 45 | { 46 | // any soaks up implicit conversions and makes the following 47 | // operator++ less-preferred than any other such operator which 48 | // might be found via ADL. 49 | struct anything { template anything(T const&); }; 50 | struct no_swap 51 | { 52 | char (& operator,(char) )[2]; 53 | }; 54 | no_swap swap(anything,anything); 55 | 56 | #if defined(BOOST_MSVC) 57 | # pragma warning(push) 58 | # pragma warning(disable: 4675) // function found through argument dependent lookup -- duh! 59 | #endif 60 | template 61 | struct has_swap_impl 62 | { 63 | static T& x; 64 | 65 | BOOST_STATIC_CONSTANT(bool, value = sizeof(swap(x,x),'x') == 1); 66 | 67 | #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) 68 | typedef boost::mpl::bool_::value> type; 69 | #else 70 | typedef boost::mpl::bool_ type; 71 | #endif 72 | }; 73 | } 74 | template 75 | struct has_swap 76 | : has_swap_::has_swap_impl::type 77 | {}; 78 | #if defined(BOOST_MSVC) 79 | # pragma warning(pop) 80 | #endif 81 | 82 | } } 83 | 84 | #endif // include guard 85 | -------------------------------------------------------------------------------- /benchmarks/deretta-coroutine/boost/coroutine/detail/index.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006, Giovanni P. Deretta 2 | // 3 | // This code may be used under either of the following two licences: 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. OF SUCH DAMAGE. 22 | // 23 | // Or: 24 | // 25 | // Distributed under the Boost Software License, Version 1.0. 26 | // (See accompanying file LICENSE_1_0.txt or copy at 27 | // http://www.boost.org/LICENSE_1_0.txt) 28 | 29 | #ifndef BOOST_COROUTINE_DETAIL_INDEX_HPP_20060613 30 | #define BOOST_COROUTINE_DETAIL_INDEX_HPP_20060613 31 | #include 32 | #include 33 | namespace boost { namespace coroutines { namespace detail { 34 | /* 35 | * Workaround for BOOST_PP_ENUM_BINARY_PARAMS, where a token 36 | * can't be createed by appending a number to a '<'. 37 | * NOTE: we are really abusing BOOST_PP_ENUM_BINARY_PARAMS, 38 | * Should simply use BOOST_PP_ENUM. 39 | */ 40 | enum {BOOST_PP_ENUM_PARAMS(BOOST_COROUTINE_ARG_MAX, index_)}; 41 | } } } 42 | #endif 43 | -------------------------------------------------------------------------------- /benchmarks/deretta-coroutine/boost/coroutine/detail/is_callable.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006, Giovanni P. Deretta 2 | // 3 | // This code may be used under either of the following two licences: 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. OF SUCH DAMAGE. 22 | // 23 | // Or: 24 | // 25 | // Distributed under the Boost Software License, Version 1.0. 26 | // (See accompanying file LICENSE_1_0.txt or copy at 27 | // http://www.boost.org/LICENSE_1_0.txt) 28 | 29 | #ifndef BOOST_COROUTINE_DETAIL_IS_CALLABLE_HPP_20060601 30 | #define BOOST_COROUTINE_DETAIL_IS_CALLABLE_HPP_20060601 31 | #include 32 | #include 33 | #include 34 | #include 35 | namespace boost { namespace coroutines { namespace detail { 36 | template 37 | struct is_function_pointer : 38 | boost::mpl::and_< 39 | boost::is_pointer, 40 | boost::is_function::type > > { 41 | typedef is_function_pointer type; 42 | }; 43 | 44 | BOOST_MPL_HAS_XXX_TRAIT_DEF(result_type); 45 | BOOST_MPL_HAS_XXX_TRAIT_DEF(result); 46 | 47 | template 48 | struct is_functor : 49 | boost::mpl::or_::type, 50 | typename has_result::type> 51 | { 52 | typedef is_functor type; 53 | }; 54 | 55 | template 56 | struct is_callable : boost::mpl::or_< 57 | is_functor, 58 | is_function_pointer >::type { 59 | typedef is_callable type; 60 | }; 61 | } } } 62 | #endif 63 | -------------------------------------------------------------------------------- /benchmarks/deretta-coroutine/boost/coroutine/detail/make_tuple_traits.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006, Giovanni P. Deretta 2 | // 3 | // This code may be used under either of the following two licences: 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. OF SUCH DAMAGE. 22 | // 23 | // Or: 24 | // 25 | // Distributed under the Boost Software License, Version 1.0. 26 | // (See accompanying file LICENSE_1_0.txt or copy at 27 | // http://www.boost.org/LICENSE_1_0.txt) 28 | 29 | #ifndef BOOST_COROUTINE_DETAIL_MAKE_TUPLE_TRAITS_HPP_20060609 30 | #define BOOST_COROUTINE_DETAIL_MAKE_TUPLE_TRAITS_HPP_20060609 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | namespace boost { namespace coroutines { namespace detail { 37 | /* 38 | * Given a mpl::vector, returns a nullary metafunction 39 | * describing a tuple of all types in the vector. 40 | * NOTE this is just wrong because it should work for all mpl 41 | * sequences, not just vectors. But it is in detail, so leave it 42 | * as is. Eventually it will be replaced by Boost.Fusion. 43 | * @p type is a tuple of all types in TypeList. 44 | * TypeList is one of mpl::vector0, mpl::vector1, etc. 45 | */ 46 | template 47 | struct make_tuple_traits; 48 | 49 | #define BOOST_COROUTINE_MAKE_TUPLE_TRAITS_GENERATOR(z, n, unused) \ 50 | template \ 51 | struct make_tuple_traits >{ \ 53 | typedef tuple_traits type; \ 54 | }; \ 55 | /**/ 56 | 57 | /** 58 | * Generate specializations of make_tuple 59 | * @note This could be done more elegantly with a recursive metafunction, 60 | * but this is simpler and works well anyway. 61 | */ 62 | BOOST_PP_REPEAT(BOOST_COROUTINE_ARG_MAX, 63 | BOOST_COROUTINE_MAKE_TUPLE_TRAITS_GENERATOR, ~); 64 | #undef BOOST_COROUTINE_MAKE_TUPLE_TRAITS_GENERATOR 65 | 66 | } } } 67 | #endif 68 | -------------------------------------------------------------------------------- /benchmarks/deretta-coroutine/boost/coroutine/detail/noreturn.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006, Giovanni P. Deretta 2 | // 3 | // This code may be used under either of the following two licences: 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. OF SUCH DAMAGE. 22 | // 23 | // Or: 24 | // 25 | // Distributed under the Boost Software License, Version 1.0. 26 | // (See accompanying file LICENSE_1_0.txt or copy at 27 | // http://www.boost.org/LICENSE_1_0.txt) 28 | 29 | #ifndef BOOST_COROUTINE_DETAIL_NORETURN_HPP_20060812 30 | #define BOOST_COROUTINE_DETAIL_NORETURN_HPP_20060812 31 | /* 32 | * The BOOST_COROUTINE_NORETURN macro provides a way to 33 | * tell the compiler that a function will not return through 34 | * the normal return path (it could return throgh a thrown exception). 35 | * This not only provieds a possible optimization hint, but also 36 | * prevents the compiler from complaining if a function that call 37 | * a noreturn function does not call return itself. 38 | */ 39 | #include 40 | 41 | #if defined(__GNUC__) 42 | 43 | #define BOOST_COROUTINE_NORETURN(function) \ 44 | function __attribute__((__noreturn__)) \ 45 | /**/ 46 | 47 | #elif defined (BOOST_MSVC) 48 | 49 | #define BOOST_COROUTINE_NORETURN(function) \ 50 | __declspec(noreturn) function \ 51 | /**/ 52 | 53 | #else 54 | //just for testing, remove the following error. 55 | #error no default 56 | #define BOOST_COROUTINE_NORETURN(function) \ 57 | function 58 | /**/ 59 | 60 | #endif 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /benchmarks/deretta-coroutine/boost/coroutine/detail/posix_utility.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006, Giovanni P. Deretta 2 | // 3 | // This code may be used under either of the following two licences: 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. OF SUCH DAMAGE. 22 | // 23 | // Or: 24 | // 25 | // Distributed under the Boost Software License, Version 1.0. 26 | // (See accompanying file LICENSE_1_0.txt or copy at 27 | // http://www.boost.org/LICENSE_1_0.txt) 28 | 29 | #ifndef BOOST_COROUTINE_DETAIL_POSIX_UTILITY_HPP_02012006 30 | #define BOOST_COROUTINE_DETAIL_POSIX_UTILITY_HPP_02012006 31 | #include 32 | 33 | #if defined(_POSIX_VERSION) 34 | /** 35 | * Most of these utilities are really pure C++, but they are useful 36 | * only on posix systems. 37 | */ 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | /** 44 | * Stack allocation routines and trampolines for setcontext 45 | */ 46 | namespace boost { namespace coroutines { namespace detail { namespace posix { 47 | 48 | 49 | //this should be a fine default. 50 | static const std::size_t stack_alignment = sizeof(void*) > 16? sizeof(void*): 16; 51 | 52 | struct stack_aligner { 53 | boost::type_with_alignment::type dummy; 54 | }; 55 | 56 | /** 57 | * Stack allocator and deleter functions. 58 | * Better implementations are possible using 59 | * mmap (might be required on some systems) and/or 60 | * using a pooling allocator. 61 | * NOTE: the SuSv3 documentation explictly allows 62 | * the use of malloc to allocate stacks for makectx. 63 | * We use free for guaranteed alignment. 64 | */ 65 | inline 66 | void* alloc_stack(std::size_t size) { 67 | return new stack_aligner[size/sizeof(stack_aligner)]; 68 | } 69 | 70 | inline 71 | void free_stack(void* stack, std::size_t size) { 72 | delete [] static_cast(stack); 73 | } 74 | 75 | /** 76 | * The splitter is needed for 64 bit systems. 77 | * @note The current implementation does NOT use 78 | * (for debug reasons). 79 | * Thus it is not 64 bit clean. 80 | * Use it for 64 bits systems. 81 | */ 82 | template 83 | union splitter { 84 | int int_[2]; 85 | T* ptr; 86 | splitter(int first, int second) { 87 | int_[0] = first; 88 | int_[1] = second; 89 | } 90 | 91 | int first() { 92 | return int_[0]; 93 | } 94 | 95 | int second() { 96 | return int_[1]; 97 | } 98 | 99 | splitter(T* ptr) :ptr(ptr) {} 100 | 101 | void operator()() { 102 | (*ptr)(); 103 | } 104 | }; 105 | 106 | template 107 | inline 108 | void 109 | trampoline_split(int first, int second) { 110 | splitter split(first, second); 111 | split(); 112 | } 113 | 114 | template 115 | inline 116 | void 117 | trampoline(T * fun) { 118 | (*fun)(); 119 | } 120 | } 121 | } } } 122 | 123 | #if defined(_POSIX_MAPPED_FILES) && _POSIX_MAPPED_FILES > 0 124 | #include 125 | namespace boost { namespace coroutines { namespace detail { namespace posix { 126 | inline 127 | void * 128 | alloc_stack_mmap(std::size_t size) { 129 | void * stack = ::mmap(NULL, 130 | size, 131 | PROT_EXEC|PROT_READ|PROT_WRITE, 132 | MAP_PRIVATE|MAP_ANONYMOUS, 133 | -1, 134 | 0 135 | ); 136 | if(stack == MAP_FAILED) { 137 | std::cerr < 32 | namespace boost { namespace coroutines { namespace detail { 33 | /* 34 | * Private interface for coroutine signaling/waiting. 35 | * These class is friend of future_impl and 36 | * its static members are invoked by asynchronous callback functions. 37 | */ 38 | struct wait_gateway { 39 | template 40 | static void wait(Future& f, int n) { 41 | f.wait(n); 42 | } 43 | 44 | template 45 | static 46 | bool waited(const Future& f) { 47 | return f.waited(); 48 | } 49 | 50 | template 51 | static 52 | void mark_wait(Future& f, bool how) { 53 | f.mark_wait(how); 54 | } 55 | 56 | template 57 | static 58 | BOOST_DEDUCED_TYPENAME 59 | Future::impl_pointer 60 | get_impl(Future& f) { 61 | return f.m_ptr; 62 | } 63 | }; 64 | 65 | 66 | } } } 67 | #endif 68 | -------------------------------------------------------------------------------- /benchmarks/deretta-coroutine/boost/coroutine/detail/signature.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006, Giovanni P. Deretta 2 | // 3 | // This code may be used under either of the following two licences: 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. OF SUCH DAMAGE. 22 | // 23 | // Or: 24 | // 25 | // Distributed under the Boost Software License, Version 1.0. 26 | // (See accompanying file LICENSE_1_0.txt or copy at 27 | // http://www.boost.org/LICENSE_1_0.txt) 28 | 29 | #ifndef BOOST_COROUTINE_DETAIL_SIGNATURE_HPP_20060609 30 | #define BOOST_COROUTINE_DETAIL_SIGNATURE_HPP_20060609 31 | #include 32 | #include 33 | namespace boost{ namespace coroutines{ namespace detail{ 34 | /* 35 | * Derived from an mpl::vector describing 36 | * 'Function' arguments types. 37 | */ 38 | template 39 | struct signature; 40 | 41 | /* 42 | * Generate specializations for the signature trait class. 43 | */ 44 | #define BOOST_COROUTINE_SIGNATURE_GENERATOR(z, n, unused) \ 45 | template \ 46 | struct signature \ 47 | : boost::mpl::BOOST_PP_CAT(vector,n)< \ 48 | BOOST_PP_ENUM_PARAMS(n,A) \ 49 | > {}; \ 50 | /**/ 51 | 52 | 53 | BOOST_PP_REPEAT(BOOST_COROUTINE_ARG_MAX, BOOST_COROUTINE_SIGNATURE_GENERATOR, ~); 54 | #undef BOOST_COROUTINE_SIGNATURE_GENERATOR 55 | } } } 56 | #endif 57 | -------------------------------------------------------------------------------- /benchmarks/deretta-coroutine/boost/coroutine/detail/swap_context.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006, Giovanni P. Deretta 2 | // 3 | // This code may be used under either of the following two licences: 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. OF SUCH DAMAGE. 22 | // 23 | // Or: 24 | // 25 | // Distributed under the Boost Software License, Version 1.0. 26 | // (See accompanying file LICENSE_1_0.txt or copy at 27 | // http://www.boost.org/LICENSE_1_0.txt) 28 | 29 | #ifndef BOOST_COROUTINE_SWAP_CONTEXT_HPP_20060611 30 | #define BOOST_COROUTINE_SWAP_CONTEXT_HPP_20060611 31 | namespace boost{ namespace coroutines { namespace detail { 32 | class default_hint {}; 33 | class yield_hint: public default_hint {}; 34 | class yield_to_hint: public default_hint {}; 35 | class invoke_hint: public default_hint {}; 36 | 37 | } } } 38 | #endif 39 | -------------------------------------------------------------------------------- /benchmarks/deretta-coroutine/boost/coroutine/detail/wait_impl.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006, Giovanni P. Deretta 2 | // 3 | // This code may be used under either of the following two licences: 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. OF SUCH DAMAGE. 22 | // 23 | // Or: 24 | // 25 | // Distributed under the Boost Software License, Version 1.0. 26 | // (See accompanying file LICENSE_1_0.txt or copy at 27 | // http://www.boost.org/LICENSE_1_0.txt) 28 | 29 | 30 | #ifndef BOOST_COROUTINE_DETAIL_WAIT_IMPL_HPP_20060728 31 | #define BOOST_COROUTINE_DETAIL_WAIT_IMPL_HPP_20060728 32 | #include 33 | #include 34 | namespace boost { namespace coroutines { namespace detail { 35 | 36 | /* 37 | * Inokes mark_wait('how') on the 'Idx'th element of 't' 38 | * then calls marker::wait with the same arguments. 39 | * returns the result of marker::wait(...) plus 1 if 40 | * the 'Idx'th.pending() is true or plus 0 otherwise. 41 | * 42 | */ 43 | template 44 | struct marker { 45 | template 46 | static int mark(Tuple& t, bool how) { 47 | wait_gateway::mark_wait(t.template get(), how); 48 | return marker::mark(t, how) + (t.template get().pending()? 1:0); 49 | 50 | } 51 | }; 52 | 53 | /* Recursion terminator */ 54 | template<> 55 | struct marker<0> { 56 | template 57 | static int mark(Tuple&, bool) { return 0;} 58 | }; 59 | 60 | template 61 | void wait_n(const Tuple& t, int n) { 62 | BOOST_STATIC_ASSERT(boost::tuples::length::value); 63 | wait_gateway::wait(t.get<0>(), n); 64 | } 65 | 66 | /* 67 | * Wait for at least one future in 'wt' tuple to be signaled. 68 | * If at least one future has been already signaled do not 69 | * block but returns immediatley (prevents deadlocks). 70 | */ 71 | template 72 | void wait_impl(Tuple wt) { 73 | try { 74 | if(marker::value>::mark(wt, true) > 0) 75 | wait_n(wt, 1); 76 | } catch (...) { 77 | marker::value>::mark(wt, false); 78 | throw; 79 | } 80 | int res = marker::value>::mark(wt, false); 81 | BOOST_ASSERT(res < boost::tuples::length::value); 82 | (void)res; 83 | } 84 | 85 | /* 86 | * Wait for all futures in 'wt' tuple to be signaled. 87 | */ 88 | template 89 | void wait_all_impl(Tuple wt) { 90 | int res = marker::value>::mark(wt, true); 91 | try { 92 | wait_n(wt, res); 93 | } catch (...) { 94 | marker::value>::mark(wt, false); 95 | throw; 96 | } 97 | res = marker::value>::mark(wt, false); 98 | BOOST_ASSERT(res == 0); 99 | } 100 | 101 | } } } 102 | #endif 103 | -------------------------------------------------------------------------------- /benchmarks/deretta-coroutine/boost/coroutine/detail/yield_result_type.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006, Giovanni P. Deretta 2 | // 3 | // This code may be used under either of the following two licences: 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. OF SUCH DAMAGE. 22 | // 23 | // Or: 24 | // 25 | // Distributed under the Boost Software License, Version 1.0. 26 | // (See accompanying file LICENSE_1_0.txt or copy at 27 | // http://www.boost.org/LICENSE_1_0.txt) 28 | 29 | #ifndef BOOST_COROUTINE_DETAIL_YIELD_RESULT_TYPE_HPP_20060609 30 | #define BOOST_COROUTINE_DETAIL_YIELD_RESULT_TYPE_HPP_20060609 31 | #include 32 | #include 33 | namespace boost{ namespace coroutines { namespace detail { 34 | /** 35 | * Same as make_tuple_traits, but if 36 | * @p TypeList is singular, @p type is the single element, and 37 | * if TypeList is empty, @p type is @p void. 38 | */ 39 | template 40 | struct yield_result_type { 41 | typedef typename make_tuple_traits::type type; 42 | }; 43 | 44 | template 45 | struct yield_result_type >{ 46 | typedef T type; 47 | }; 48 | 49 | template<> 50 | struct yield_result_type >{ 51 | typedef void type; 52 | }; 53 | } } } 54 | #endif 55 | -------------------------------------------------------------------------------- /benchmarks/deretta-coroutine/boost/coroutine/exception.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006, Giovanni P. Deretta 2 | // 3 | // This code may be used under either of the following two licences: 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. OF SUCH DAMAGE. 22 | // 23 | // Or: 24 | // 25 | // Distributed under the Boost Software License, Version 1.0. 26 | // (See accompanying file LICENSE_1_0.txt or copy at 27 | // http://www.boost.org/LICENSE_1_0.txt) 28 | 29 | #ifndef BOOST_COROUTINE_EXCEPTION_HPP_20060601 30 | #define BOOST_COROUTINE_EXCEPTION_HPP_20060601 31 | #include 32 | #include 33 | namespace boost { namespace coroutines { 34 | 35 | // All coroutine exceptions are derived from this base. 36 | class exception_base : public std::exception {}; 37 | 38 | // This exception is thrown when a coroutine is requested 39 | // to exit. 40 | class exit_exception: public exception_base {}; 41 | 42 | // This exception is thrown on a coroutine invocation 43 | // if a coroutine exits without 44 | // returning a result. Note that calling invoke() 45 | // on an already exited coroutine is undefined behaviour. 46 | class coroutine_exited: public exception_base {}; 47 | 48 | // This exception is thrown on a coroutine invocation 49 | // if a coroutine enter the wait state without 50 | // returning a result. Note that calling invoke() 51 | // on a waiting coroutine is undefined behaviour. 52 | class waiting : public exception_base {}; 53 | 54 | class unknown_exception_tag {}; 55 | 56 | // This exception is thrown on a coroutine invocation 57 | // if the coroutine is exited by an uncatched exception 58 | // (not derived from exit_exception). abnormal_exit::type() 59 | // returns the typeid of that exception if it is derived 60 | // from std::exception, else returns typeid(unknonw_exception_tag) 61 | class abnormal_exit : public std::exception { 62 | public: 63 | abnormal_exit(std::type_info const& e) : 64 | m_e (e) {}; 65 | 66 | const char* what() const throw() { 67 | return m_e == typeid(unknown_exception_tag)? 68 | "unknown exception" : 69 | m_e.name(); 70 | } 71 | 72 | std::type_info const& type() const throw() { 73 | return m_e; 74 | } 75 | private: 76 | std::type_info const& m_e; 77 | }; 78 | } } 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /benchmarks/deretta-coroutine/boost/coroutine/shared_coroutine.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006, Giovanni P. Deretta 2 | // 3 | // This code may be used under either of the following two licences: 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. OF SUCH DAMAGE. 22 | // 23 | // Or: 24 | // 25 | // Distributed under the Boost Software License, Version 1.0. 26 | // (See accompanying file LICENSE_1_0.txt or copy at 27 | // http://www.boost.org/LICENSE_1_0.txt) 28 | 29 | #ifndef BOOST_COROUTINE_SHARED_COROUTINE_HPP_20060812 30 | #define BOOST_COROUTINE_SHARED_COROUTINE_HPP_20060812 31 | #include 32 | namespace boost { namespace coroutines { 33 | // This class is a workaround for the widespread lack of move 34 | // semantics support. It is a refrence counted wrapper around 35 | // the coroutine object. 36 | // FIXME: ATM a shared_coroutine is-a coroutine. This is to avoid 37 | // inheriting privately and cluttering the code with lots of using 38 | // declarations to unhide coroutine members and nested types. 39 | // From a purity point of view, coroutines and shared_coroutines should 40 | // be two different types. 41 | template 42 | class shared_coroutine : public coroutine { 43 | public: 44 | typedef coroutine coroutine_type; 45 | 46 | shared_coroutine() {} 47 | 48 | template 49 | shared_coroutine(Functor f, 50 | std::ptrdiff_t stack_size = 51 | detail::default_stack_size) : 52 | coroutine_type(f, stack_size) {} 53 | 54 | shared_coroutine(move_from src): 55 | coroutine_type(src) {} 56 | 57 | shared_coroutine(const shared_coroutine& rhs) : 58 | coroutine_type(rhs.m_pimpl.get(), detail::init_from_impl_tag()) {} 59 | 60 | shared_coroutine& operator=(move_from src) { 61 | shared_coroutine(src).swap(*this); 62 | return *this; 63 | } 64 | 65 | shared_coroutine& operator=(const shared_coroutine& rhs) { 66 | shared_coroutine(rhs).swap(*this); 67 | return *this; 68 | } 69 | private: 70 | }; 71 | } } 72 | #endif 73 | -------------------------------------------------------------------------------- /benchmarks/deretta-coroutine/boost/coroutine/tags: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bombela/CxxCoroutine/dee6aac5b1436cef359f17447248641bcc52bbc2/benchmarks/deretta-coroutine/boost/coroutine/tags -------------------------------------------------------------------------------- /benchmarks/deretta-coroutine/libs/coroutine/benchmark/Jamfile: -------------------------------------------------------------------------------- 1 | subproject libs/coroutine/benchmark ; 2 | 3 | project boost : $(BOOST_ROOT) ; 4 | 5 | flags gcc CFLAGS speed: -finline ; 6 | 7 | template example 8 | : ../build/boost_coroutine 9 | : ../../.. 10 | ; 11 | 12 | exe call_overhead : call_overhead.cpp out_of_line.cpp