From 22850775ca9869892856b1fc6573f15775871060 Mon Sep 17 00:00:00 2001 From: Oliver Kowalke Date: Tue, 15 Jul 2014 20:33:14 +0200 Subject: [PATCH] variadric tempalte args --- examples/{ => cpp03}/Jamfile.v2 | 2 +- examples/{ => cpp03}/asio/daytime_client.cpp | 0 examples/{ => cpp03}/asio/daytime_client2.cpp | 0 examples/{ => cpp03}/asio/detail/spawn.hpp | 2 +- .../{ => cpp03}/asio/detail/use_future.hpp | 0 examples/{ => cpp03}/asio/detail/yield.hpp | 0 examples/{ => cpp03}/asio/echo_client.cpp | 0 examples/{ => cpp03}/asio/echo_client2.cpp | 0 examples/{ => cpp03}/asio/echo_server.cpp | 0 examples/{ => cpp03}/asio/echo_server2.cpp | 0 examples/{ => cpp03}/asio/loop.hpp | 0 .../asio/publish_subscribe/publisher.cpp | 0 .../asio/publish_subscribe/server.cpp | 0 .../asio/publish_subscribe/subscriber.cpp | 0 examples/{ => cpp03}/asio/spawn.hpp | 0 examples/{ => cpp03}/asio/use_future.hpp | 0 examples/{ => cpp03}/asio/yield.hpp | 0 examples/{ => cpp03}/barrier.cpp | 0 examples/{ => cpp03}/future.cpp | 0 examples/{ => cpp03}/futures_mt.cpp | 0 examples/{ => cpp03}/interrupt.cpp | 0 examples/{ => cpp03}/join.cpp | 0 examples/{ => cpp03}/migrate_fibers.cpp | 0 examples/{ => cpp03}/ping_pong.cpp | 0 examples/{ => cpp03}/segmented_stack.cpp | 0 examples/{ => cpp03}/simple.cpp | 0 .../{ => cpp03}/workstealing_round_robin.cpp | 0 .../{ => cpp03}/workstealing_round_robin.hpp | 0 examples/cpp11/Jamfile.v2 | 32 +++ examples/cpp11/future.cpp | 44 ++++ examples/cpp11/simple.cpp | 39 ++++ include/boost/fiber/fiber.hpp | 216 +++++++++++++----- include/boost/fiber/future/packaged_task.hpp | 20 +- performance/clock.hpp | 8 +- performance/fiber/overhead_detach.cpp | 4 +- performance/fiber/overhead_future.cpp | 2 +- performance/fiber/overhead_join.cpp | 4 +- performance/fiber/overhead_join_multiple.cpp | 14 +- performance/fiber/overhead_yield.cpp | 4 +- src/fiber.cpp | 2 +- 40 files changed, 306 insertions(+), 87 deletions(-) rename examples/{ => cpp03}/Jamfile.v2 (97%) rename examples/{ => cpp03}/asio/daytime_client.cpp (100%) rename examples/{ => cpp03}/asio/daytime_client2.cpp (100%) rename examples/{ => cpp03}/asio/detail/spawn.hpp (99%) rename examples/{ => cpp03}/asio/detail/use_future.hpp (100%) rename examples/{ => cpp03}/asio/detail/yield.hpp (100%) rename examples/{ => cpp03}/asio/echo_client.cpp (100%) rename examples/{ => cpp03}/asio/echo_client2.cpp (100%) rename examples/{ => cpp03}/asio/echo_server.cpp (100%) rename examples/{ => cpp03}/asio/echo_server2.cpp (100%) rename examples/{ => cpp03}/asio/loop.hpp (100%) rename examples/{ => cpp03}/asio/publish_subscribe/publisher.cpp (100%) rename examples/{ => cpp03}/asio/publish_subscribe/server.cpp (100%) rename examples/{ => cpp03}/asio/publish_subscribe/subscriber.cpp (100%) rename examples/{ => cpp03}/asio/spawn.hpp (100%) rename examples/{ => cpp03}/asio/use_future.hpp (100%) rename examples/{ => cpp03}/asio/yield.hpp (100%) rename examples/{ => cpp03}/barrier.cpp (100%) rename examples/{ => cpp03}/future.cpp (100%) rename examples/{ => cpp03}/futures_mt.cpp (100%) rename examples/{ => cpp03}/interrupt.cpp (100%) rename examples/{ => cpp03}/join.cpp (100%) rename examples/{ => cpp03}/migrate_fibers.cpp (100%) rename examples/{ => cpp03}/ping_pong.cpp (100%) rename examples/{ => cpp03}/segmented_stack.cpp (100%) rename examples/{ => cpp03}/simple.cpp (100%) rename examples/{ => cpp03}/workstealing_round_robin.cpp (100%) rename examples/{ => cpp03}/workstealing_round_robin.hpp (100%) create mode 100644 examples/cpp11/Jamfile.v2 create mode 100644 examples/cpp11/future.cpp create mode 100644 examples/cpp11/simple.cpp diff --git a/examples/Jamfile.v2 b/examples/cpp03/Jamfile.v2 similarity index 97% rename from examples/Jamfile.v2 rename to examples/cpp03/Jamfile.v2 index 2bc45ea6..289eda22 100644 --- a/examples/Jamfile.v2 +++ b/examples/cpp03/Jamfile.v2 @@ -16,7 +16,7 @@ import toolset ; project boost/fiber/example : requirements - ../build//boost_fiber + ../../build//boost_fiber /boost/atomic//boost_atomic /boost/coroutine//boost_coroutine /boost/system//boost_system diff --git a/examples/asio/daytime_client.cpp b/examples/cpp03/asio/daytime_client.cpp similarity index 100% rename from examples/asio/daytime_client.cpp rename to examples/cpp03/asio/daytime_client.cpp diff --git a/examples/asio/daytime_client2.cpp b/examples/cpp03/asio/daytime_client2.cpp similarity index 100% rename from examples/asio/daytime_client2.cpp rename to examples/cpp03/asio/daytime_client2.cpp diff --git a/examples/asio/detail/spawn.hpp b/examples/cpp03/asio/detail/spawn.hpp similarity index 99% rename from examples/asio/detail/spawn.hpp rename to examples/cpp03/asio/detail/spawn.hpp index 350ddb92..b9949acc 100644 --- a/examples/asio/detail/spawn.hpp +++ b/examples/cpp03/asio/detail/spawn.hpp @@ -271,7 +271,7 @@ struct spawn_helper void operator()() { fiber_entry_point< Handler, Function > entry_point = { data_ }; - boost::fibers::fiber fiber( entry_point, attributes_); + boost::fibers::fiber fiber( attributes_, entry_point); fiber.detach(); } diff --git a/examples/asio/detail/use_future.hpp b/examples/cpp03/asio/detail/use_future.hpp similarity index 100% rename from examples/asio/detail/use_future.hpp rename to examples/cpp03/asio/detail/use_future.hpp diff --git a/examples/asio/detail/yield.hpp b/examples/cpp03/asio/detail/yield.hpp similarity index 100% rename from examples/asio/detail/yield.hpp rename to examples/cpp03/asio/detail/yield.hpp diff --git a/examples/asio/echo_client.cpp b/examples/cpp03/asio/echo_client.cpp similarity index 100% rename from examples/asio/echo_client.cpp rename to examples/cpp03/asio/echo_client.cpp diff --git a/examples/asio/echo_client2.cpp b/examples/cpp03/asio/echo_client2.cpp similarity index 100% rename from examples/asio/echo_client2.cpp rename to examples/cpp03/asio/echo_client2.cpp diff --git a/examples/asio/echo_server.cpp b/examples/cpp03/asio/echo_server.cpp similarity index 100% rename from examples/asio/echo_server.cpp rename to examples/cpp03/asio/echo_server.cpp diff --git a/examples/asio/echo_server2.cpp b/examples/cpp03/asio/echo_server2.cpp similarity index 100% rename from examples/asio/echo_server2.cpp rename to examples/cpp03/asio/echo_server2.cpp diff --git a/examples/asio/loop.hpp b/examples/cpp03/asio/loop.hpp similarity index 100% rename from examples/asio/loop.hpp rename to examples/cpp03/asio/loop.hpp diff --git a/examples/asio/publish_subscribe/publisher.cpp b/examples/cpp03/asio/publish_subscribe/publisher.cpp similarity index 100% rename from examples/asio/publish_subscribe/publisher.cpp rename to examples/cpp03/asio/publish_subscribe/publisher.cpp diff --git a/examples/asio/publish_subscribe/server.cpp b/examples/cpp03/asio/publish_subscribe/server.cpp similarity index 100% rename from examples/asio/publish_subscribe/server.cpp rename to examples/cpp03/asio/publish_subscribe/server.cpp diff --git a/examples/asio/publish_subscribe/subscriber.cpp b/examples/cpp03/asio/publish_subscribe/subscriber.cpp similarity index 100% rename from examples/asio/publish_subscribe/subscriber.cpp rename to examples/cpp03/asio/publish_subscribe/subscriber.cpp diff --git a/examples/asio/spawn.hpp b/examples/cpp03/asio/spawn.hpp similarity index 100% rename from examples/asio/spawn.hpp rename to examples/cpp03/asio/spawn.hpp diff --git a/examples/asio/use_future.hpp b/examples/cpp03/asio/use_future.hpp similarity index 100% rename from examples/asio/use_future.hpp rename to examples/cpp03/asio/use_future.hpp diff --git a/examples/asio/yield.hpp b/examples/cpp03/asio/yield.hpp similarity index 100% rename from examples/asio/yield.hpp rename to examples/cpp03/asio/yield.hpp diff --git a/examples/barrier.cpp b/examples/cpp03/barrier.cpp similarity index 100% rename from examples/barrier.cpp rename to examples/cpp03/barrier.cpp diff --git a/examples/future.cpp b/examples/cpp03/future.cpp similarity index 100% rename from examples/future.cpp rename to examples/cpp03/future.cpp diff --git a/examples/futures_mt.cpp b/examples/cpp03/futures_mt.cpp similarity index 100% rename from examples/futures_mt.cpp rename to examples/cpp03/futures_mt.cpp diff --git a/examples/interrupt.cpp b/examples/cpp03/interrupt.cpp similarity index 100% rename from examples/interrupt.cpp rename to examples/cpp03/interrupt.cpp diff --git a/examples/join.cpp b/examples/cpp03/join.cpp similarity index 100% rename from examples/join.cpp rename to examples/cpp03/join.cpp diff --git a/examples/migrate_fibers.cpp b/examples/cpp03/migrate_fibers.cpp similarity index 100% rename from examples/migrate_fibers.cpp rename to examples/cpp03/migrate_fibers.cpp diff --git a/examples/ping_pong.cpp b/examples/cpp03/ping_pong.cpp similarity index 100% rename from examples/ping_pong.cpp rename to examples/cpp03/ping_pong.cpp diff --git a/examples/segmented_stack.cpp b/examples/cpp03/segmented_stack.cpp similarity index 100% rename from examples/segmented_stack.cpp rename to examples/cpp03/segmented_stack.cpp diff --git a/examples/simple.cpp b/examples/cpp03/simple.cpp similarity index 100% rename from examples/simple.cpp rename to examples/cpp03/simple.cpp diff --git a/examples/workstealing_round_robin.cpp b/examples/cpp03/workstealing_round_robin.cpp similarity index 100% rename from examples/workstealing_round_robin.cpp rename to examples/cpp03/workstealing_round_robin.cpp diff --git a/examples/workstealing_round_robin.hpp b/examples/cpp03/workstealing_round_robin.hpp similarity index 100% rename from examples/workstealing_round_robin.hpp rename to examples/cpp03/workstealing_round_robin.hpp diff --git a/examples/cpp11/Jamfile.v2 b/examples/cpp11/Jamfile.v2 new file mode 100644 index 00000000..336557fb --- /dev/null +++ b/examples/cpp11/Jamfile.v2 @@ -0,0 +1,32 @@ +# Boost.Fiber Library Examples Jamfile + +# Copyright Oliver Kowalke 2013. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +# For more information, see http://www.boost.org/ + +import common ; +import feature ; +import indirect ; +import modules ; +import os ; +import toolset ; + +project boost/fiber/example + : requirements + ../../build//boost_fiber + /boost/atomic//boost_atomic + /boost/coroutine//boost_coroutine + /boost/system//boost_system + /boost/thread//boost_thread + gcc-4.7,on:-fsplit-stack + gcc-4.7,on:-DBOOST_USE_SEGMENTED_STACKS + gcc-4.8,on:-fsplit-stack + gcc-4.8,on:-DBOOST_USE_SEGMENTED_STACKS + static + multi + ; + +exe simple : simple.cpp ; diff --git a/examples/cpp11/future.cpp b/examples/cpp11/future.cpp new file mode 100644 index 00000000..9b0256ed --- /dev/null +++ b/examples/cpp11/future.cpp @@ -0,0 +1,44 @@ +#include +#include +#include + +#include +#include + +#include + +inline +int fn( std::string const& str, int n) +{ + for ( int i = 0; i < n; ++i) + { + std::cout << i << ": " << str << std::endl; + boost::this_fiber::yield(); + } + + return n; +} + +void start() +{ + boost::fibers::future< int > fi( + boost::fibers::async( fn, "abc", 5) ); + fi.wait(); + std::cout << "fn() returned " << fi.get() << std::endl; +} + +int main() +{ + try + { + boost::fibers::fiber( start).join(); + std::cout << "done." << std::endl; + + return EXIT_SUCCESS; + } + catch ( std::exception const& e) + { std::cerr << "exception: " << e.what() << std::endl; } + catch (...) + { std::cerr << "unhandled exception" << std::endl; } + return EXIT_FAILURE; +} diff --git a/examples/cpp11/simple.cpp b/examples/cpp11/simple.cpp new file mode 100644 index 00000000..6c58f046 --- /dev/null +++ b/examples/cpp11/simple.cpp @@ -0,0 +1,39 @@ +#include +#include +#include + +#include +#include + +#include + +inline +void fn( std::string const& str, int n) +{ + for ( int i = 0; i < n; ++i) + { + std::cout << i << ": " << str << std::endl; + boost::this_fiber::yield(); + } +} + +int main() +{ + try + { + boost::fibers::fiber f1( fn, "abc", 5); + boost::fibers::fiber f2( fn, "xyz", 7); + + f1.join(); + f2.join(); + + std::cout << "done." << std::endl; + + return EXIT_SUCCESS; + } + catch ( std::exception const& e) + { std::cerr << "exception: " << e.what() << std::endl; } + catch (...) + { std::cerr << "unhandled exception" << std::endl; } + return EXIT_FAILURE; +} diff --git a/include/boost/fiber/fiber.hpp b/include/boost/fiber/fiber.hpp index 686942d6..c1fca25f 100644 --- a/include/boost/fiber/fiber.hpp +++ b/include/boost/fiber/fiber.hpp @@ -17,6 +17,7 @@ #include #include #include +#include // boost::allocator_arg_t #include #include @@ -60,7 +61,44 @@ private: BOOST_MOVABLE_BUT_NOT_COPYABLE( fiber); - void start_fiber_(); +#ifdef BOOST_MSVC + typedef void ( * fiber_fn)(); + + template< typename StackAllocator > + void setup_( StackAllocator const& stack_alloc, attributes const& attrs, fiber_fn fn) + { + coro_t::call_type coro( detail::trampoline< fiber_fn >, attrs, stack_alloc); + detail::setup< Fn > s( forward< fiber_fn >( fn), & coro); + impl_.reset( s.allocate() ); + BOOST_ASSERT( impl_); + } +#endif + +#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES + template< typename StackAllocator, typename Fn > + void setup_( StackAllocator const& stack_alloc, attributes const& attrs, Fn fn) + { + typename coro_t::call_type coro( detail::trampoline< Fn >, attrs, stack_alloc); + detail::setup< Fn > s( forward< Fn >( fn), & coro); + impl_.reset( s.allocate() ); + BOOST_ASSERT( impl_); + } +#endif + + template< typename StackAllocator, typename Fn > + void setup_( StackAllocator const& stack_alloc, attributes const& attrs, BOOST_RV_REF( Fn) fn) + { + typename coro_t::call_type coro( detail::trampoline< Fn >, attrs, stack_alloc); +#ifdef BOOST_NO_RVALUE_REFERENCES + detail::setup< Fn > s( fn, & coro); +#else + detail::setup< Fn > s( forward< Fn >( fn), & coro); +#endif + impl_.reset( s.allocate() ); + BOOST_ASSERT( impl_); + } + + void start_(); public: typedef detail::worker_fiber::id id; @@ -74,96 +112,170 @@ public: {} #ifdef BOOST_MSVC - typedef void ( * fiber_fn)(); - - explicit fiber( fiber_fn fn, attributes const& attrs = attributes(), - stack_allocator const& stack_alloc = stack_allocator() ) : + fiber( fiber_fn fn) : impl_() { - coro_t::call_type coro( detail::trampoline< fiber_fn >, attrs, stack_alloc); - detail::setup< fiber_fn > s( forward< fiber_fn >( fn), & coro); - impl_.reset( s.allocate() ); - BOOST_ASSERT( impl_); + attributes attrs; + stack_allocator stack_alloc; + setup_( stack_alloc, attrs, fn); + start_(); + } - start_fiber_(); + fiber( attributes const& attrs, fiber_fn fn) : + impl_() + { + stack_allocator stack_alloc; + setup_( stack_alloc, attrs, fn); + start_(); } template< typename StackAllocator > - explicit fiber( fiber_fn fn, attributes const& attrs, - StackAllocator const& stack_alloc) : + fiber( boost::allocator_arg_t, StackAllocator const& stack_alloc, fiber_fn fn) : impl_() { - typename coro_t::call_type coro( detail::trampoline< fiber_fn >, attrs, stack_alloc); - detail::setup< fiber_fn > s( forward< fiber_fn >( fn), & coro); - impl_.reset( s.allocate() ); - BOOST_ASSERT( impl_); + attributes attrs; + setup_( stack_alloc, attrs, fn); + start_(); + } - start_fiber_(); + template< typename StackAllocator > + fiber( boost::allocator_arg_t, StackAllocator const& stack_alloc, attributes const& attrs, fiber_fn fn) : + impl_() + { + setup_( stack_alloc, attrs, fn); + start_(); } #endif #ifdef BOOST_NO_RVALUE_REFERENCES template< typename Fn > - explicit fiber( Fn fn, attributes const& attrs = attributes(), - stack_allocator const& stack_alloc = stack_allocator() ) : + fiber( Fn fn) : impl_() { - typename coro_t::call_type coro( detail::trampoline< Fn >, attrs, stack_alloc); - detail::setup< Fn > s( fn, & coro); - impl_.reset( s.allocate() ); - BOOST_ASSERT( impl_); - - start_fiber_(); + attributes attrs; + stack_allocator stack_alloc; + setup_( stack_alloc, attrs, fn); + start_(); } - template< typename Fn, typename StackAllocator > - explicit fiber( Fn fn, attributes const& attrs, - StackAllocator const& stack_alloc) : + template< typename Fn > + fiber( attributes const& attrs, Fn fn) : impl_() { - typename coro_t::call_type coro( detail::trampoline< Fn >, attrs, stack_alloc); - detail::setup< Fn > s( fn, & coro); - impl_.reset( s.allocate() ); - BOOST_ASSERT( impl_); + stack_allocator stack_alloc; + setup_( stack_alloc, attrs, fn); + start_(); + } - start_fiber_(); + template< typename StackAllocator, typename Fn > + fiber( boost::allocator_arg_t, StackAllocator const& stack_alloc, Fn fn) : + impl_() + { + attributes attrs; + setup_( stack_alloc, attrs, fn); + start_(); + } + + template< typename StackAllocator, typename Fn > + fiber( boost::allocator_arg_t, StackAllocator const& stack_alloc, attributes const& attrs, Fn fn) : + impl_() + { + setup_( stack_alloc, attrs, fn); + start_(); } #endif template< typename Fn > - explicit fiber( BOOST_RV_REF( Fn) fn, attributes const& attrs = attributes(), - stack_allocator const& stack_alloc = stack_allocator() ) : + fiber( BOOST_RV_REF( Fn) fn) : impl_() { - typename coro_t::call_type coro( detail::trampoline< Fn >, attrs, stack_alloc); + attributes attrs; + stack_allocator stack_alloc; #ifdef BOOST_NO_RVALUE_REFERENCES - detail::setup< Fn > s( fn, & coro); + setup_( stack_alloc, attrs, fn); #else - detail::setup< Fn > s( forward< Fn >( fn), & coro); + setup_( stack_alloc, attrs, forward< Fn >( fn) ); #endif - impl_.reset( s.allocate() ); - BOOST_ASSERT( impl_); - - start_fiber_(); + start_(); } - template< typename Fn, typename StackAllocator > - explicit fiber( BOOST_RV_REF( Fn) fn, attributes const& attrs, - StackAllocator const& stack_alloc) : + template< typename Fn > + fiber( attributes const& attrs, BOOST_RV_REF( Fn) fn) : impl_() { - typename coro_t::call_type coro( detail::trampoline< Fn >, attrs, stack_alloc); + stack_allocator stack_alloc; #ifdef BOOST_NO_RVALUE_REFERENCES - detail::setup< Fn > s( fn, & coro); + setup_( stack_alloc, attrs, fn); #else - detail::setup< Fn > s( forward< Fn >( fn), & coro); + setup_( stack_alloc, attrs, forward< Fn >( fn) ); #endif - impl_.reset( s.allocate() ); - BOOST_ASSERT( impl_); - - start_fiber_(); + start_(); } + template< typename StackAllocator, typename Fn > + fiber( boost::allocator_arg_t, StackAllocator const& stack_alloc, BOOST_RV_REF( Fn) fn) : + impl_() + { + attributes attrs; +#ifdef BOOST_NO_RVALUE_REFERENCES + setup_( stack_alloc, attrs, fn); +#else + setup_( stack_alloc, attrs, forward< Fn >( fn) ); +#endif + start_(); + } + + template< typename StackAllocator, typename Fn > + fiber( boost::allocator_arg_t, StackAllocator const& stack_alloc, attributes const& attrs, BOOST_RV_REF( Fn) fn) : + impl_() + { +#ifdef BOOST_NO_RVALUE_REFERENCES + setup_( stack_alloc, attrs, fn); +#else + setup_( stack_alloc, attrs, forward< Fn >( fn) ); +#endif + start_(); + } + +#ifdef BOOST_FIBERS_USE_VARIADIC_FIBER + template< typename Fn, class ... Args > + fiber( BOOST_RV_REF( Fn) fn, BOOST_RV_REF( Args) ... args) : + impl_() + { + attributes attrs; + stack_allocator stack_alloc; + setup_( stack_alloc, attrs, std::bind( fn, std::forward< Args >( args) ... ) ); + start_(); + } + + template< typename Fn, class ... Args > + fiber( attributes const& attrs, BOOST_RV_REF( Fn) fn, BOOST_RV_REF( Args) ... args) : + impl_() + { + stack_allocator stack_alloc; + setup_( stack_alloc, attrs, std::bind( fn, std::forward< Args >( args) ... ) ); + start_(); + } + + template< typename StackAllocator, typename Fn, class ... Args > + fiber( boost::allocator_arg_t, StackAllocator const& stack_alloc, BOOST_RV_REF( Fn) fn, BOOST_RV_REF( Args) ... args) : + impl_() + { + attributes attrs; + setup_( stack_alloc, attrs, std::bind( fn, std::forward< Args >( args) ... ) ); + start_(); + } + + template< typename StackAllocator, typename Fn, class ... Args > + fiber( boost::allocator_arg_t, StackAllocator const& stack_alloc, attributes const& attrs, + BOOST_RV_REF( Fn) fn, BOOST_RV_REF( Args) ... args) : + impl_() + { + setup_( stack_alloc, attrs, std::bind( fn, std::forward< Args >( args) ... ) ); + start_(); + } +#endif + ~fiber() { if ( joinable() ) std::terminate(); } diff --git a/include/boost/fiber/future/packaged_task.hpp b/include/boost/fiber/future/packaged_task.hpp index 4ea7adb5..c0d76c67 100644 --- a/include/boost/fiber/future/packaged_task.hpp +++ b/include/boost/fiber/future/packaged_task.hpp @@ -85,7 +85,7 @@ public: } template< typename Allocator > - explicit packaged_task( boost::allocator_arg_t, Allocator const& alloc, task_fn const& fn) : + packaged_task( boost::allocator_arg_t, Allocator const& alloc, task_fn const& fn) : obtained_( false), task_() { @@ -108,7 +108,7 @@ public: #ifdef BOOST_NO_RVALUE_REFERENCES template< typename Fn > - explicit packaged_task( Fn fn) : + packaged_task( Fn fn) : obtained_( false), task_() { @@ -128,7 +128,7 @@ public: } template< typename Fn, typename Allocator > - explicit packaged_task( boost::allocator_arg_t, Allocator const& alloc, Fn const& fn) : + packaged_task( boost::allocator_arg_t, Allocator const& alloc, Fn const& fn) : obtained_( false), task_() { @@ -150,7 +150,7 @@ public: #endif template< typename Fn > - explicit packaged_task( BOOST_RV_REF( Fn) fn) : + packaged_task( BOOST_RV_REF( Fn) fn) : obtained_( false), task_() { @@ -174,7 +174,7 @@ public: } template< typename Fn, typename Allocator > - explicit packaged_task( boost::allocator_arg_t, Allocator const& alloc, BOOST_RV_REF( Fn) fn) : + packaged_task( boost::allocator_arg_t, Allocator const& alloc, BOOST_RV_REF( Fn) fn) : obtained_( false), task_() { @@ -334,7 +334,7 @@ public: } template< typename Allocator > - explicit packaged_task( Allocator const& alloc, task_fn const& fn) : + packaged_task( Allocator const& alloc, task_fn const& fn) : obtained_( false), task_() { @@ -357,7 +357,7 @@ public: #ifdef BOOST_NO_RVALUE_REFERENCES template< typename Fn > - explicit packaged_task( Fn fn) : + packaged_task( Fn fn) : obtained_( false), task_() { @@ -377,7 +377,7 @@ public: } template< typename Fn, typename Allocator > - explicit packaged_task( Allocator const& alloc, Fn const& fn) : + packaged_task( Allocator const& alloc, Fn const& fn) : obtained_( false), task_() { @@ -399,7 +399,7 @@ public: #endif template< typename Fn > - explicit packaged_task( BOOST_RV_REF( Fn) fn) : + packaged_task( BOOST_RV_REF( Fn) fn) : obtained_( false), task_() { @@ -423,7 +423,7 @@ public: } template< typename Fn, typename Allocator > - explicit packaged_task( Allocator const& alloc, BOOST_RV_REF( Fn) fn) : + packaged_task( Allocator const& alloc, BOOST_RV_REF( Fn) fn) : obtained_( false), task_() { diff --git a/performance/clock.hpp b/performance/clock.hpp index 5ca3cff7..6103951f 100644 --- a/performance/clock.hpp +++ b/performance/clock.hpp @@ -17,15 +17,15 @@ #include typedef boost::chrono::high_resolution_clock clock_type; -typedef chronoduration duration_type; -typedef chronotime_point time_point_type; +typedef clock_type::duration duration_type; +typedef clock_type::time_point time_point_type; struct clock_overhead { boost::uint64_t operator()() { - time_point_type start( chrononow() ); - return ( chrononow() - start).count(); + time_point_type start( clock_type::now() ); + return ( clock_type::now() - start).count(); } }; diff --git a/performance/fiber/overhead_detach.cpp b/performance/fiber/overhead_detach.cpp index 757705a5..5e20e437 100644 --- a/performance/fiber/overhead_detach.cpp +++ b/performance/fiber/overhead_detach.cpp @@ -29,11 +29,11 @@ template< typename StackAllocator > duration_type measure( duration_type overhead, StackAllocator const& stack_alloc) { boost::fibers::attributes attrs( unwind_stack, preserve_fpu); - boost::fibers::fiber( worker, attrs).join(); + boost::fibers::fiber( stack_alloc, attrs, worker).join(); time_point_type start( clock_type::now() ); for ( std::size_t i = 0; i < jobs; ++i) { - boost::fibers::fiber( worker, attrs).detach(); + boost::fibers::fiber( stack_alloc, attrs, worker).detach(); } duration_type total = clock_type::now() - start; total -= overhead_clock(); // overhead of measurement diff --git a/performance/fiber/overhead_future.cpp b/performance/fiber/overhead_future.cpp index 0981f700..081b7e50 100644 --- a/performance/fiber/overhead_future.cpp +++ b/performance/fiber/overhead_future.cpp @@ -30,7 +30,7 @@ void test_future( boost::fibers::attributes const& attrs, StackAllocator const& { boost::fibers::packaged_task< void() > pt( worker); boost::fibers::future< void > f( pt.get_future() ); - boost::fibers::fiber( boost::move( pt), attrs).detach(); + boost::fibers::fiber( stack_alloc, attrs, boost::move( pt) ).detach(); f.wait(); } diff --git a/performance/fiber/overhead_join.cpp b/performance/fiber/overhead_join.cpp index 1d3cb17a..d1d5a71b 100644 --- a/performance/fiber/overhead_join.cpp +++ b/performance/fiber/overhead_join.cpp @@ -29,11 +29,11 @@ template< typename StackAllocator > duration_type measure( duration_type overhead, StackAllocator const& stack_alloc) { boost::fibers::attributes attrs( unwind_stack, preserve_fpu); - boost::fibers::fiber( worker, attrs).join(); + boost::fibers::fiber( stack_alloc, attrs, worker).join(); time_point_type start( clock_type::now() ); for ( std::size_t i = 0; i < jobs; ++i) { - boost::fibers::fiber( worker, attrs).join(); + boost::fibers::fiber( stack_alloc, attrs, worker).join(); } duration_type total = clock_type::now() - start; total -= overhead_clock(); // overhead of measurement diff --git a/performance/fiber/overhead_join_multiple.cpp b/performance/fiber/overhead_join_multiple.cpp index c9f79b5b..43653837 100644 --- a/performance/fiber/overhead_join_multiple.cpp +++ b/performance/fiber/overhead_join_multiple.cpp @@ -21,7 +21,7 @@ #include "../preallocated_stack_allocator.hpp" #define JOBS 100 -#define CREATE(z, n, x) boost::fibers::fiber BOOST_PP_CAT(f,n) ( worker, attrs); +#define CREATE(z, n, x) boost::fibers::fiber BOOST_PP_CAT(f,n) ( attrs, worker); #define JOIN(z, n, x) BOOST_PP_CAT(f,n).join(); boost::coroutines::flag_fpu_t preserve_fpu = boost::coroutines::fpu_not_preserved; @@ -29,8 +29,7 @@ boost::coroutines::flag_unwind_t unwind_stack = boost::coroutines::no_stack_unwi void worker() {} -template< typename StackAllocator > -duration_type measure( duration_type overhead, StackAllocator const& stack_alloc) +duration_type measure( duration_type overhead) { boost::fibers::attributes attrs( unwind_stack, preserve_fpu); @@ -46,13 +45,6 @@ duration_type measure( duration_type overhead, StackAllocator const& stack_alloc return total; } -duration_type measure_standard( duration_type overhead) -{ - boost::fibers::stack_allocator stack_alloc; - - return measure( overhead, stack_alloc); -} - int main( int argc, char * argv[]) { try @@ -85,7 +77,7 @@ int main( int argc, char * argv[]) duration_type overhead = overhead_clock(); std::cout << "overhead " << overhead.count() << " nano seconds" << std::endl; - boost::uint64_t res = measure_standard( overhead).count(); + boost::uint64_t res = measure( overhead).count(); std::cout << "average of " << res << " nano seconds" << std::endl; return EXIT_SUCCESS; diff --git a/performance/fiber/overhead_yield.cpp b/performance/fiber/overhead_yield.cpp index a036dfaf..dcc15fae 100644 --- a/performance/fiber/overhead_yield.cpp +++ b/performance/fiber/overhead_yield.cpp @@ -30,11 +30,11 @@ template< typename StackAllocator > duration_type measure( duration_type overhead, StackAllocator const& stack_alloc) { boost::fibers::attributes attrs( unwind_stack, preserve_fpu); - boost::fibers::fiber( worker, attrs).join(); + boost::fibers::fiber( attrs, worker).join(); time_point_type start( clock_type::now() ); for ( std::size_t i = 0; i < jobs; ++i) { - boost::fibers::fiber( worker, attrs).join(); + boost::fibers::fiber( attrs, worker).join(); } duration_type total = clock_type::now() - start; total -= overhead_clock(); // overhead of measurement diff --git a/src/fiber.cpp b/src/fiber.cpp index 84b7bc1d..f70b798c 100644 --- a/src/fiber.cpp +++ b/src/fiber.cpp @@ -22,7 +22,7 @@ namespace boost { namespace fibers { void -fiber::start_fiber_() +fiber::start_() { impl_->set_ready(); fm_spawn( impl_.get() );