2
0
mirror of https://github.com/boostorg/fiber.git synced 2026-02-09 11:02:53 +00:00

interruption

This commit is contained in:
Oliver Kowalke
2013-01-10 19:51:34 +01:00
parent f18136562f
commit cff07a3645
10 changed files with 158 additions and 74 deletions

72
src/interruption.cpp Normal file
View File

@@ -0,0 +1,72 @@
// 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/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_enabled() && interruption_requested() )
throw fibers::fiber_interrupted();
}
}}
#ifdef BOOST_HAS_ABI_HEADERS
# include BOOST_ABI_SUFFIX
#endif