|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r57488 - in sandbox/fiber: boost/fiber boost/fiber/detail libs/fiber/test
From: oliver.kowalke_at_[hidden]
Date: 2009-11-08 11:18:39
Author: olli
Date: 2009-11-08 11:18:38 EST (Sun, 08 Nov 2009)
New Revision: 57488
URL: http://svn.boost.org/trac/boost/changeset/57488
Log:
- some work
Text files modified:
sandbox/fiber/boost/fiber/detail/fiber_info_posix.hpp | 6 +++---
sandbox/fiber/boost/fiber/scheduler.hpp | 2 ++
sandbox/fiber/boost/fiber/utility.hpp | 4 ++++
sandbox/fiber/libs/fiber/test/test_utility.cpp | 34 ++++++++++++++++++++++++++++++++++
4 files changed, 43 insertions(+), 3 deletions(-)
Modified: sandbox/fiber/boost/fiber/detail/fiber_info_posix.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/detail/fiber_info_posix.hpp (original)
+++ sandbox/fiber/boost/fiber/detail/fiber_info_posix.hpp 2009-11-08 11:18:38 EST (Sun, 08 Nov 2009)
@@ -4,8 +4,8 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-#ifndef BOOST_FIBER_DETAIL_FIBER_INFO_BASE_POSIX_H
-#define BOOST_FIBER_DETAIL_FIBER_INFO_BASE_POSIX_H
+#ifndef BOOST_FIBER_DETAIL_FIBER_INFO_POSIX_H
+#define BOOST_FIBER_DETAIL_FIBER_INFO_POSIX_H
extern "C" {
@@ -83,4 +83,4 @@
#include <boost/config/abi_suffix.hpp>
-#endif // BOOST_FIBER_DETAIL_FIBER_INFO_BASE_POSIX_H
+#endif // BOOST_FIBER_DETAIL_FIBER_INFO_POSIX_H
Modified: sandbox/fiber/boost/fiber/scheduler.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/scheduler.hpp (original)
+++ sandbox/fiber/boost/fiber/scheduler.hpp 2009-11-08 11:18:38 EST (Sun, 08 Nov 2009)
@@ -29,6 +29,7 @@
bool runs_as_fiber();
fiber::fiber::id get_id();
void yield();
+void cancel();
}
@@ -41,6 +42,7 @@
friend bool this_fiber::runs_as_fiber();
friend fiber::id this_fiber::get_id();
friend void this_fiber::yield();
+ friend void this_fiber::cancel();
typedef thread_specific_ptr< policy > tss_policy_t;
Modified: sandbox/fiber/boost/fiber/utility.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/utility.hpp (original)
+++ sandbox/fiber/boost/fiber/utility.hpp 2009-11-08 11:18:38 EST (Sun, 08 Nov 2009)
@@ -32,6 +32,10 @@
{ fiber::scheduler::yield(); }
inline
+void cancel()
+{ fiber::scheduler::exit(); }
+
+inline
void sleep( system_time const& abs_time)
{}
Modified: sandbox/fiber/libs/fiber/test/test_utility.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/test/test_utility.cpp (original)
+++ sandbox/fiber/libs/fiber/test/test_utility.cpp 2009-11-08 11:18:38 EST (Sun, 08 Nov 2009)
@@ -4,6 +4,7 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
+#include <stdexcept>
#include <sstream>
#include <string>
@@ -35,6 +36,17 @@
}
}
+void cancel_fn( int n)
+{
+ if ( n < 3) throw std::invalid_argument("must be greater than 3");
+ for ( int i = 0; i < n; ++i)
+ {
+ if ( i == 2) boost::this_fiber::cancel();
+ ++value;
+ boost::this_fiber::yield();
+ }
+}
+
void test_case_1()
{
boost::fiber::scheduler sched;
@@ -58,6 +70,7 @@
void test_case_3()
{
+ value = 0;
boost::fiber::scheduler sched;
sched.make_fiber( yield_fn, 3);
BOOST_CHECK_EQUAL( 0, value);
@@ -78,6 +91,26 @@
BOOST_CHECK_EQUAL( 3, value);
}
+void test_case_4()
+{
+ value = 0;
+ boost::fiber::scheduler sched;
+ sched.make_fiber( cancel_fn, 5);
+ BOOST_CHECK_EQUAL( 0, value);
+
+ BOOST_CHECK( sched.run() );
+ BOOST_CHECK_EQUAL( 1, value);
+
+ BOOST_CHECK( sched.run() );
+ BOOST_CHECK_EQUAL( 2, value);
+
+ BOOST_CHECK( sched.run() );
+ BOOST_CHECK( sched.empty() );
+ BOOST_CHECK_EQUAL( std::size_t( 0), sched.size() );
+ BOOST_CHECK( ! sched.run() );
+ BOOST_CHECK_EQUAL( 2, value);
+}
+
boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
{
boost::unit_test::test_suite * test =
@@ -86,6 +119,7 @@
test->add( BOOST_TEST_CASE( & test_case_1) );
test->add( BOOST_TEST_CASE( & test_case_2) );
test->add( BOOST_TEST_CASE( & test_case_3) );
+ test->add( BOOST_TEST_CASE( & test_case_4) );
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