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

scheduler::swap()

This commit is contained in:
Oliver Kowalke
2012-12-15 14:36:39 +01:00
parent fb79b6eccb
commit f306dcc391
3 changed files with 20 additions and 0 deletions

View File

@@ -100,6 +100,8 @@ private:
public:
static scheduler & instance();
static void swap( scheduler *) BOOST_NOEXCEPT;
virtual void spawn( detail::fiber_base::ptr_t const&) = 0;
virtual void join( detail::fiber_base::ptr_t const&) = 0;

View File

@@ -5,6 +5,8 @@
#define BOOST_FIBERS_SOURCE
#include <algorithm>
#include <boost/fiber/scheduler.hpp>
#include <boost/fiber/detail/default_scheduler.hpp>
@@ -32,6 +34,10 @@ scheduler::instance()
return * instance_;
}
void
scheduler::swap( scheduler * sched)
{ std::swap( instance_, sched); }
}}
#ifdef BOOST_HAS_ABI_HEADERS

View File

@@ -14,6 +14,7 @@
#include <boost/utility.hpp>
#include <boost/fiber/all.hpp>
#include <boost/fiber/detail/default_scheduler.hpp>
namespace stm = boost::fibers;
namespace this_stm = boost::this_fiber;
@@ -180,6 +181,16 @@ void test_detach()
BOOST_CHECK( ! s2);
}
void test_swap()
{
stm::scheduler::swap(
new stm::detail::default_scheduler() );
stm::fiber s1( f1);
BOOST_CHECK( ! s1);
stm::fiber s2( f2);
BOOST_CHECK( s2);
}
void test_complete()
{
stm::fiber s1( f1);
@@ -330,6 +341,7 @@ boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
test->add( BOOST_TEST_CASE( & test_id) );
test->add( BOOST_TEST_CASE( & test_detach) );
test->add( BOOST_TEST_CASE( & test_complete) );
test->add( BOOST_TEST_CASE( & test_swap) );
test->add( BOOST_TEST_CASE( & test_cancel) );
test->add( BOOST_TEST_CASE( & test_join) );
test->add( BOOST_TEST_CASE( & test_yield_break) );