2
0
mirror of https://github.com/boostorg/fiber.git synced 2026-02-17 13:42:21 +00:00

Add BOOST_ASSERT_MSG in case properties() called when null.

This could either be because the thread's current sched_algorithm is not a
subclass of sched_algorithm_with_properties (e.g. set_scheduling_algorithm()
was never called for this thread, so round_robin is in use), or because the
fiber has not yet reached execution. A fiber's properties are instantiated
when it is first scheduled.
This commit is contained in:
Nat Goodspeed
2015-06-20 12:00:11 -04:00
parent 9778fc8594
commit 97e132abd6
2 changed files with 8 additions and 2 deletions

View File

@@ -137,7 +137,9 @@ public:
template< typename PROPS >
PROPS & properties() {
return dynamic_cast< PROPS & >( * impl_->get_properties() );
fiber_properties* props = impl_->get_properties();
BOOST_ASSERT_MSG(props, "fiber::properties not set");
return dynamic_cast< PROPS & >( * props );
}
};

View File

@@ -10,6 +10,7 @@
#include <mutex> // std::unique_lock
#include <boost/config.hpp>
#include <boost/assert.hpp>
#include <boost/fiber/detail/config.hpp>
#include <boost/fiber/detail/scheduler.hpp>
@@ -51,7 +52,10 @@ void sleep_for( std::chrono::duration< Rep, Period > const& timeout_duration) {
template< typename PROPS >
PROPS & properties() {
return dynamic_cast< PROPS & >( * fibers::detail::scheduler::instance()->active()->get_properties() );
fibers::fiber_properties* props =
fibers::detail::scheduler::instance()->active()->get_properties();
BOOST_ASSERT_MSG(props, "this_fiber::properties not set");
return dynamic_cast< PROPS & >( * props );
}
} // this_fiber