mirror of
https://github.com/boostorg/fiber.git
synced 2026-02-02 20:52:21 +00:00
78 lines
2.1 KiB
C++
78 lines
2.1 KiB
C++
|
|
// Copyright Oliver Kowalke 2009.
|
|
// 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)
|
|
|
|
#define BOOST_FIBERS_SOURCE
|
|
|
|
#include <boost/fiber/interruption.hpp>
|
|
|
|
#include <boost/throw_exception.hpp>
|
|
|
|
#include <boost/fiber/detail/interrupt_flags.hpp>
|
|
#include <boost/fiber/detail/scheduler.hpp>
|
|
#include <boost/fiber/exceptions.hpp>
|
|
#include <boost/fiber/operations.hpp>
|
|
|
|
#ifdef BOOST_HAS_ABI_HEADERS
|
|
# include BOOST_ABI_PREFIX
|
|
#endif
|
|
|
|
namespace boost {
|
|
namespace this_fiber {
|
|
|
|
disable_interruption::disable_interruption() :
|
|
set_( ( fibers::detail::scheduler::instance().active()->interruption_blocked() ) )
|
|
{
|
|
if ( ! set_)
|
|
fibers::detail::scheduler::instance().active()->interruption_blocked( true);
|
|
}
|
|
|
|
disable_interruption::~disable_interruption()
|
|
{
|
|
if ( ! set_)
|
|
fibers::detail::scheduler::instance().active()->interruption_blocked( false);
|
|
}
|
|
|
|
restore_interruption::restore_interruption( disable_interruption & disabler) :
|
|
disabler_( disabler)
|
|
{
|
|
if ( ! disabler_.set_)
|
|
fibers::detail::scheduler::instance().active()->interruption_blocked( false);
|
|
}
|
|
|
|
restore_interruption::~restore_interruption()
|
|
{
|
|
if ( ! disabler_.set_)
|
|
fibers::detail::scheduler::instance().active()->interruption_blocked( true);
|
|
}
|
|
|
|
bool interruption_enabled() BOOST_NOEXCEPT
|
|
{
|
|
fibers::detail::fiber_base::ptr_t f( fibers::detail::scheduler::instance().active() );
|
|
return f && f->interruption_enabled();
|
|
}
|
|
|
|
bool interruption_requested() BOOST_NOEXCEPT
|
|
{
|
|
fibers::detail::fiber_base::ptr_t f( fibers::detail::scheduler::instance().active() );
|
|
if ( ! f) return false;
|
|
return f->interruption_requested();
|
|
}
|
|
|
|
void interruption_point()
|
|
{
|
|
if ( interruption_requested() && interruption_enabled() )
|
|
{
|
|
fibers::detail::scheduler::instance().active()->request_interruption( false);
|
|
boost::throw_exception( fibers::fiber_interrupted() );
|
|
}
|
|
}
|
|
|
|
}}
|
|
|
|
#ifdef BOOST_HAS_ABI_HEADERS
|
|
# include BOOST_ABI_SUFFIX
|
|
#endif
|