$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r57658 - in sandbox/fiber: boost/fiber boost/fiber/detail libs/fiber/src libs/fiber/test
From: oliver.kowalke_at_[hidden]
Date: 2009-11-14 14:10:36
Author: olli
Date: 2009-11-14 14:10:35 EST (Sat, 14 Nov 2009)
New Revision: 57658
URL: http://svn.boost.org/trac/boost/changeset/57658
Log:
- priority()/priority( int) added + unit test
Added:
   sandbox/fiber/libs/fiber/test/test_priority.cpp   (contents, props changed)
Text files modified: 
   sandbox/fiber/boost/fiber/attributes.hpp            |     6 +++---                                  
   sandbox/fiber/boost/fiber/detail/scheduler_impl.hpp |     8 +++++++-                                
   sandbox/fiber/boost/fiber/fiber.hpp                 |     4 ++++                                    
   sandbox/fiber/boost/fiber/scheduler.hpp             |    10 ++++++++++                              
   sandbox/fiber/boost/fiber/utility.hpp               |     8 ++++++++                                
   sandbox/fiber/libs/fiber/src/attributes.cpp         |     4 ++--                                    
   sandbox/fiber/libs/fiber/src/fiber.cpp              |    18 ++++++++++++++++--                      
   sandbox/fiber/libs/fiber/src/scheduler.cpp          |    24 ++++++++++++++++++++++++                
   sandbox/fiber/libs/fiber/src/scheduler_impl.cpp     |    40 +++++++++++++++++++++++++++++++++++++++-
   sandbox/fiber/libs/fiber/test/Jamfile.v2            |     1 +                                       
   10 files changed, 114 insertions(+), 9 deletions(-)
Modified: sandbox/fiber/boost/fiber/attributes.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/attributes.hpp	(original)
+++ sandbox/fiber/boost/fiber/attributes.hpp	2009-11-14 14:10:35 EST (Sat, 14 Nov 2009)
@@ -20,7 +20,7 @@
 {
 private:
         std::size_t		stacksize_;
-	std::size_t		priority_;
+	int				priority_;
 
 public:
         attributes();
@@ -29,9 +29,9 @@
 
         std::size_t stack_size() const;
 
-	void priority( std::size_t);
+	void priority( int);
 
-	std::size_t priority() const;
+	int priority() const;
 };
 
 }}
Modified: sandbox/fiber/boost/fiber/detail/scheduler_impl.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/detail/scheduler_impl.hpp	(original)
+++ sandbox/fiber/boost/fiber/detail/scheduler_impl.hpp	2009-11-14 14:10:35 EST (Sat, 14 Nov 2009)
@@ -41,7 +41,7 @@
 
         void add_fiber( fiber);
 
-	fiber::id active_fiber();
+	fiber::id active_fiber() const;
 
         void yield_active_fiber();
 
@@ -55,6 +55,12 @@
 
         void resume_fiber( fiber::id const&);
 
+	int priority( fiber::id const&);
+
+	void priority( fiber::id const&, int);
+
+	void re_schedule( fiber::id const&);
+
         bool run();
 
         bool empty();
Modified: sandbox/fiber/boost/fiber/fiber.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/fiber.hpp	(original)
+++ sandbox/fiber/boost/fiber/fiber.hpp	2009-11-14 14:10:35 EST (Sat, 14 Nov 2009)
@@ -188,6 +188,10 @@
 
         bool is_alive() const;
 
+	int priority() const;
+
+	void priority( int);
+
         void cancel();
 
         void suspend();
Modified: sandbox/fiber/boost/fiber/scheduler.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/scheduler.hpp	(original)
+++ sandbox/fiber/boost/fiber/scheduler.hpp	2009-11-14 14:10:35 EST (Sat, 14 Nov 2009)
@@ -30,6 +30,8 @@
 void yield();
 void cancel();
 void suspend();
+int priority();
+void priority( int);
 
 }
 
@@ -43,6 +45,8 @@
         friend void this_fiber::yield();
         friend void this_fiber::cancel();
         friend void this_fiber::suspend();
+	friend int this_fiber::priority();
+	friend void this_fiber::priority( int);
         friend class fiber;
 
         typedef thread_specific_ptr< detail::scheduler_impl >	tss_impl_t;
@@ -65,6 +69,12 @@
 
         static void resume_fiber( fiber::id const&);
 
+	static int priority( fiber::id const&);
+
+	static void priority( fiber::id const&, int);
+
+	static void re_schedule( fiber::id const&);
+
         detail::scheduler_impl * access_();
 
 public:
Modified: sandbox/fiber/boost/fiber/utility.hpp
==============================================================================
--- sandbox/fiber/boost/fiber/utility.hpp	(original)
+++ sandbox/fiber/boost/fiber/utility.hpp	2009-11-14 14:10:35 EST (Sat, 14 Nov 2009)
@@ -39,6 +39,14 @@
 void suspend()
 { fibers::scheduler::suspend_active_fiber(); }
 
+inline
+int priority()
+{ return fibers::scheduler::priority( get_id() ); }
+
+inline
+void priority( int prio)
+{ fibers::scheduler::priority( get_id(), prio); }
+
 }}
 
 #include <boost/config/abi_suffix.hpp>
Modified: sandbox/fiber/libs/fiber/src/attributes.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/attributes.cpp	(original)
+++ sandbox/fiber/libs/fiber/src/attributes.cpp	2009-11-14 14:10:35 EST (Sat, 14 Nov 2009)
@@ -31,10 +31,10 @@
 { return stacksize_; }
 
 void
-attributes::priority( std::size_t value)
+attributes::priority( int value)
 { priority_ = value; }
 
-std::size_t
+int
 attributes::priority() const
 { return priority_; }
 
Modified: sandbox/fiber/libs/fiber/src/fiber.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/fiber.cpp	(original)
+++ sandbox/fiber/libs/fiber/src/fiber.cpp	2009-11-14 14:10:35 EST (Sat, 14 Nov 2009)
@@ -104,11 +104,25 @@
 bool
 fiber::is_alive() const
 {
-	if ( ! info_)
-		throw fiber_moved();
+	if ( ! info_) throw fiber_moved();
         return ( info_->state & IS_ALIVE_BIT_MASK) != 0;
 }
 
+int
+fiber::priority() const
+{
+	if ( ! info_) throw fiber_moved();
+	return info_->attrs.priority();
+}
+
+void
+fiber::priority( int prio)
+{
+	if ( ! info_) throw fiber_moved();
+	info_->attrs.priority( prio);
+	if ( is_alive() ) scheduler::re_schedule( get_id() );
+}
+
 void
 fiber::cancel()
 { scheduler::cancel_fiber( get_id() ); }
Modified: sandbox/fiber/libs/fiber/src/scheduler.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/scheduler.cpp	(original)
+++ sandbox/fiber/libs/fiber/src/scheduler.cpp	2009-11-14 14:10:35 EST (Sat, 14 Nov 2009)
@@ -77,6 +77,30 @@
         impl->resume_fiber( f_id);
 }
 
+int
+scheduler::priority( fiber::id const& f_id)
+{
+	detail::scheduler_impl * impl( impl_.get() );
+	if (  ! impl) throw fiber_error("not a fiber");
+	return impl->priority( f_id);
+}
+
+void
+scheduler::priority( fiber::id const& f_id, int prio)
+{
+	detail::scheduler_impl * impl( impl_.get() );
+	if (  ! impl) throw fiber_error("not a fiber");
+	impl->priority( f_id, prio);
+	re_schedule( f_id);
+}
+
+void
+scheduler::re_schedule( fiber::id const& f_id)
+{
+	detail::scheduler_impl * impl( impl_.get() );
+	impl->re_schedule( f_id);
+}
+
 detail::scheduler_impl *
 scheduler::access_()
 {
Modified: sandbox/fiber/libs/fiber/src/scheduler_impl.cpp
==============================================================================
--- sandbox/fiber/libs/fiber/src/scheduler_impl.cpp	(original)
+++ sandbox/fiber/libs/fiber/src/scheduler_impl.cpp	2009-11-14 14:10:35 EST (Sat, 14 Nov 2009)
@@ -67,7 +67,7 @@
 }
 
 fiber::id
-scheduler_impl::active_fiber()
+scheduler_impl::active_fiber() const
 { return f_id_; }
 
 void
@@ -196,6 +196,44 @@
         }
 }
 
+int
+scheduler_impl::priority( fiber::id const& f_id)
+{
+	container::iterator i = fibers_.find( f_id);
+	if ( i == fibers_.end() ) throw scheduler_error("fiber not found");
+	fiber f( i->second);
+	BOOST_ASSERT( f);
+	BOOST_ASSERT( ! HAS_STATE_MASTER( f.info_->state) );
+
+	return f.info_->attrs.priority();
+}
+
+void
+scheduler_impl::priority( fiber::id const& f_id, int prio)
+{
+	container::iterator i = fibers_.find( f_id);
+	if ( i == fibers_.end() ) throw scheduler_error("fiber not found");
+	fiber f( i->second);
+	BOOST_ASSERT( f);
+	BOOST_ASSERT( ! HAS_STATE_MASTER( f.info_->state) );
+
+	f.info_->attrs.priority( prio);
+	re_schedule( f_id);
+}
+
+void
+scheduler_impl::re_schedule( fiber::id const& f_id)
+{
+	container::iterator i = fibers_.find( f_id);
+	if ( i == fibers_.end() ) return;
+	fiber f( i->second);
+	BOOST_ASSERT( f);
+	BOOST_ASSERT( ! HAS_STATE_MASTER( f.info_->state) );
+
+	// TODO: re-schedule fiber == remove from
+	// runnable_fibers + re-insert
+}
+
 bool
 scheduler_impl::run()
 {
Modified: sandbox/fiber/libs/fiber/test/Jamfile.v2
==============================================================================
--- sandbox/fiber/libs/fiber/test/Jamfile.v2	(original)
+++ sandbox/fiber/libs/fiber/test/Jamfile.v2	2009-11-14 14:10:35 EST (Sat, 14 Nov 2009)
@@ -30,6 +30,7 @@
     [ fiber-test test_utility ]
     [ fiber-test test_cancel ]
     [ fiber-test test_suspended ]
+    [ fiber-test test_priority ]
     [ fiber-test test_mutex ]
     [ fiber-test test_auto_reset_event ]
     [ fiber-test test_manual_reset_event ]
Added: sandbox/fiber/libs/fiber/test/test_priority.cpp
==============================================================================
--- (empty file)
+++ sandbox/fiber/libs/fiber/test/test_priority.cpp	2009-11-14 14:10:35 EST (Sat, 14 Nov 2009)
@@ -0,0 +1,39 @@
+
+//          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)
+
+#include <sstream>
+#include <string>
+
+#include <boost/test/unit_test.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/fiber.hpp>
+
+
+void zero_args_fn()
+{}
+
+void test_case_1()
+{
+	boost::fiber f( zero_args_fn);
+	BOOST_CHECK_EQUAL( 0, f.priority() );
+
+	f.priority( 5);
+	BOOST_CHECK_EQUAL( 5, f.priority() );
+
+	f.priority( -5);
+	BOOST_CHECK_EQUAL( -5, f.priority() );
+}
+
+boost::unit_test::test_suite * init_unit_test_suite( int, char* [])
+{
+	boost::unit_test::test_suite * test =
+		BOOST_TEST_SUITE("Boost.Fiber: priority test suite");
+
+	test->add( BOOST_TEST_CASE( & test_case_1) );
+
+	return test;
+}