From 97e132abd62d3ed28c7cd3db0e3e130fc48c7da8 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Sat, 20 Jun 2015 12:00:11 -0400 Subject: [PATCH] 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. --- include/boost/fiber/fiber.hpp | 4 +++- include/boost/fiber/operations.hpp | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/boost/fiber/fiber.hpp b/include/boost/fiber/fiber.hpp index 418d032a..577cf8dc 100644 --- a/include/boost/fiber/fiber.hpp +++ b/include/boost/fiber/fiber.hpp @@ -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 ); } }; diff --git a/include/boost/fiber/operations.hpp b/include/boost/fiber/operations.hpp index f79a8236..0d54589d 100644 --- a/include/boost/fiber/operations.hpp +++ b/include/boost/fiber/operations.hpp @@ -10,6 +10,7 @@ #include // std::unique_lock #include +#include #include #include @@ -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