properties.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright Nat Goodspeed 2014.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // Define fiber_properties, a base class from which a library consumer can
  6. // derive a subclass with specific properties important to a user-coded
  7. // scheduler.
  8. #ifndef BOOST_FIBERS_PROPERTIES_HPP
  9. #define BOOST_FIBERS_PROPERTIES_HPP
  10. #include <boost/fiber/detail/config.hpp>
  11. #ifdef BOOST_HAS_ABI_HEADERS
  12. # include BOOST_ABI_PREFIX
  13. #endif
  14. # if defined(BOOST_MSVC)
  15. # pragma warning(push)
  16. # pragma warning(disable:4275)
  17. # endif
  18. namespace boost {
  19. namespace fibers {
  20. class context;
  21. namespace algo {
  22. class algorithm;
  23. }
  24. class BOOST_FIBERS_DECL fiber_properties {
  25. protected:
  26. // initialized by constructor
  27. context * ctx_;
  28. // set every time this fiber becomes READY
  29. algo::algorithm * algo_{ nullptr };
  30. // Inform the relevant algorithm instance that something important
  31. // has changed, so it can (presumably) adjust its data structures
  32. // accordingly.
  33. void notify() noexcept;
  34. public:
  35. // Any specific property setter method, after updating the relevant
  36. // instance variable, can/should call notify().
  37. // fiber_properties, and by implication every subclass, must accept a back
  38. // pointer to its context.
  39. explicit fiber_properties( context * ctx) noexcept :
  40. ctx_{ ctx } {
  41. }
  42. // We need a virtual destructor (hence a vtable) because fiber_properties
  43. // is stored polymorphically (as fiber_properties*) in context, and
  44. // destroyed via that pointer.
  45. virtual ~fiber_properties() = default;
  46. // not really intended for public use, but algorithm_with_properties
  47. // must be able to call this
  48. void set_algorithm( algo::algorithm * algo) noexcept {
  49. algo_ = algo;
  50. }
  51. };
  52. }} // namespace boost::fibers
  53. # if defined(BOOST_MSVC)
  54. # pragma warning(pop)
  55. # endif
  56. #ifdef BOOST_HAS_ABI_HEADERS
  57. # include BOOST_ABI_SUFFIX
  58. #endif
  59. #endif // BOOST_FIBERS_PROPERTIES_HPP