|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r58339 - in sandbox/fiber: boost/fiber libs/fiber/test
From: oliver.kowalke_at_[hidden]
Date: 2009-12-13 04:54:08
Author: olli
Date: 2009-12-13 04:54:07 EST (Sun, 13 Dec 2009)
New Revision: 58339
URL: http://svn.boost.org/trac/boost/changeset/58339
Log:
- migrate overloaded for passing only the fiber
Text files modified:
sandbox/fiber/boost/fiber/fiber.hpp | 4 ++
sandbox/fiber/boost/fiber/scheduler.hpp | 10 ++++++
sandbox/fiber/libs/fiber/test/test_scheduler.cpp | 64 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 78 insertions(+), 0 deletions(-)
Modified: sandbox/fiber/boost/fiber/fiber.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/fiber.hpp (original)
+++ sandbox/fiber/boost/fiber/fiber.hpp 2009-12-13 04:54:07 EST (Sun, 13 Dec 2009)
@@ -33,11 +33,15 @@
#define BOOST_FIBER_DEFAULT_STACKSIZE 64000
+template< typename Strategy >
+class scheduler;
class strategy;
class BOOST_FIBER_DECL fiber
{
private:
+ template< typename Strategy >
+ friend class scheduler;
friend class strategy;
struct dummy;
Modified: sandbox/fiber/boost/fiber/scheduler.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/scheduler.hpp (original)
+++ sandbox/fiber/boost/fiber/scheduler.hpp 2009-12-13 04:54:07 EST (Sun, 13 Dec 2009)
@@ -15,6 +15,7 @@
#include <boost/utility.hpp>
#include <boost/fiber/detail/config.hpp>
+#include <boost/fiber/exceptions.hpp>
#include <boost/fiber/fiber.hpp>
#include <boost/fiber/round_robin.hpp>
#include <boost/fiber/strategy.hpp>
@@ -77,6 +78,15 @@
void make_fiber( std::size_t stack_size, Fn fn)
{ strategy_->add( fiber( stack_size, fn) ); }
+ void migrate_fiber( fiber f)
+ {
+ if ( ! f) throw fiber_moved();
+
+ strategy * st( f.info_()->st);
+ if ( ! st) throw fiber_error("fiber not attached");
+ strategy_->migrate( f.info_()->st->release( f.get_id() ) );
+ }
+
template< typename OtherStrategy >
void migrate_fiber( fiber::id const& id, scheduler< OtherStrategy > & other)
{ strategy_->migrate( other.strategy_->release( id) ); }
Modified: sandbox/fiber/libs/fiber/test/test_scheduler.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/test/test_scheduler.cpp (original)
+++ sandbox/fiber/libs/fiber/test/test_scheduler.cpp 2009-12-13 04:54:07 EST (Sun, 13 Dec 2009)
@@ -343,6 +343,69 @@
BOOST_CHECK_EQUAL( 3, value2);
}
+void test_case_7()
+{
+ value1 = 0;
+ value2 = 0;
+
+ boost::fibers::scheduler<> sched1, sched2;
+
+ boost::fiber f( & yield1_fn);
+ boost::fiber::id id = f.get_id();
+ sched1.submit_fiber( f);
+ sched2.make_fiber( & yield2_fn);
+
+ BOOST_CHECK( ! sched1.empty() );
+ BOOST_CHECK( ! sched2.empty() );
+ BOOST_CHECK_EQUAL( std::size_t( 1), sched1.size() );
+ BOOST_CHECK_EQUAL( std::size_t( 1), sched2.size() );
+ BOOST_CHECK_EQUAL( 0, value1);
+ BOOST_CHECK_EQUAL( 0, value2);
+
+ BOOST_CHECK( sched1.run() );
+ BOOST_CHECK( ! sched1.empty() );
+ BOOST_CHECK_EQUAL( std::size_t( 1), sched1.size() );
+ BOOST_CHECK_EQUAL( 1, value1);
+ BOOST_CHECK_EQUAL( 0, value2);
+
+ BOOST_CHECK( sched2.run() );
+ BOOST_CHECK( ! sched2.empty() );
+ BOOST_CHECK_EQUAL( std::size_t( 1), sched2.size() );
+ BOOST_CHECK_EQUAL( 1, value1);
+ BOOST_CHECK_EQUAL( 1, value2);
+
+ BOOST_CHECK( sched1.run() );
+ BOOST_CHECK( ! sched1.empty() );
+ BOOST_CHECK_EQUAL( std::size_t( 1), sched1.size() );
+ BOOST_CHECK_EQUAL( 2, value1);
+ BOOST_CHECK_EQUAL( 1, value2);
+
+ BOOST_CHECK( sched2.run() );
+ BOOST_CHECK( ! sched2.empty() );
+ BOOST_CHECK_EQUAL( std::size_t( 1), sched2.size() );
+ BOOST_CHECK_EQUAL( 2, value1);
+ BOOST_CHECK_EQUAL( 2, value2);
+
+ sched2.migrate_fiber( f);
+ BOOST_CHECK_EQUAL( std::size_t( 0), sched1.size() );
+ BOOST_CHECK_EQUAL( std::size_t( 2), sched2.size() );
+
+ BOOST_CHECK( ! sched1.run() );
+ BOOST_CHECK( sched1.empty() );
+
+ BOOST_CHECK( sched2.run() );
+ BOOST_CHECK( ! sched2.empty() );
+ BOOST_CHECK_EQUAL( std::size_t( 2), sched2.size() );
+ BOOST_CHECK_EQUAL( 2, value1);
+ BOOST_CHECK_EQUAL( 3, value2);
+
+ BOOST_CHECK( sched2.run() );
+ BOOST_CHECK( ! sched2.empty() );
+ BOOST_CHECK_EQUAL( std::size_t( 2), sched2.size() );
+ BOOST_CHECK_EQUAL( 3, value1);
+ BOOST_CHECK_EQUAL( 3, value2);
+}
+
boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
{
boost::unit_test::test_suite * test =
@@ -354,6 +417,7 @@
test->add( BOOST_TEST_CASE( & test_case_4) );
test->add( BOOST_TEST_CASE( & test_case_5) );
test->add( BOOST_TEST_CASE( & test_case_6) );
+ test->add( BOOST_TEST_CASE( & test_case_7) );
return test;
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk