2 // Copyright Oliver Kowalke 2013.
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 #include "boost/fiber/fiber.hpp"
9 #include <system_error>
11 #include <boost/assert.hpp>
13 #include "boost/fiber/exceptions.hpp"
14 #include "boost/fiber/scheduler.hpp"
16 #ifdef BOOST_HAS_ABI_HEADERS
17 # include BOOST_ABI_PREFIX
24 fiber::start_() noexcept {
25 context * ctx = context::active();
26 ctx->attach( impl_.get() );
27 switch ( impl_->get_policy() ) {
29 // push new fiber to ready-queue
30 // resume executing current fiber
31 ctx->get_scheduler()->schedule( impl_.get() );
33 case launch::dispatch:
34 // resume new fiber and push current fiber
39 BOOST_ASSERT_MSG( false, "unknown launch-policy");
45 // FIXME: must fiber::join() be synchronized?
46 if ( context::active()->get_id() == get_id() ) {
47 throw fiber_error{ std::make_error_code( std::errc::resource_deadlock_would_occur),
48 "boost fiber: trying to join itself" };
51 throw fiber_error{ std::make_error_code( std::errc::invalid_argument),
52 "boost fiber: fiber not joinable" };
61 throw fiber_error{ std::make_error_code( std::errc::invalid_argument),
62 "boost fiber: fiber not joinable" };
69 #ifdef BOOST_HAS_ABI_HEADERS
70 # include BOOST_ABI_SUFFIX