diff --git a/ClockReceiver/JustInTime.hpp b/ClockReceiver/JustInTime.hpp index 6d5a89583..0894f4da2 100644 --- a/ClockReceiver/JustInTime.hpp +++ b/ClockReceiver/JustInTime.hpp @@ -10,6 +10,7 @@ #define JustInTime_h #include "../Concurrency/AsyncTaskQueue.hpp" +#include "ClockingHintSource.hpp" #include "ForceInline.hpp" /*! @@ -24,8 +25,13 @@ If the held object implements get_next_sequence_point() then it'll be used to flush implicitly as and when sequence points are hit. Callers can use will_flush() to predict these. + + If the held object is a subclass of ClockingHint::Source, this template will register as an + observer and potentially stop clocking or stop delaying clocking until just-in-time references + as directed. */ -template class JustInTimeActor { +template class JustInTimeActor: + public ClockingHint::Observer { private: class SequencePointAwareDeleter { public: @@ -43,10 +49,20 @@ template JustInTimeActor(Args&&... args) : object_(std::forward(args)...) {} + template JustInTimeActor(Args&&... args) : object_(std::forward(args)...) { + if constexpr (std::is_base_of::value) { + object_.set_clocking_hint_observer(this); + } + } /// Adds time to the actor. forceinline void operator += (LocalTimeScale rhs) { + if constexpr (std::is_base_of::value) { + if(clocking_preference_ == ClockingHint::Preference::None) { + return; + } + } + if constexpr (multiplier != 1) { time_since_update_ += rhs * multiplier; } else { @@ -54,11 +70,17 @@ template ::value) { + if (clocking_preference_ == ClockingHint::Preference::RealTime) { + flush(); + return; + } + } + if constexpr (has_sequence_points::value) { time_until_event_ -= rhs; if(time_until_event_ <= LocalTimeScale(0)) { flush(); - update_sequence_point(); } } } @@ -149,6 +171,11 @@ template struct has_sequence_points : std::false_type {}; template struct has_sequence_points().get_next_sequence_point()))> : std::true_type {}; + + ClockingHint::Preference clocking_preference_ = ClockingHint::Preference::JustInTime; + void set_component_prefers_clocking(ClockingHint::Source *, ClockingHint::Preference clocking) { + clocking_preference_ = clocking; + } }; /*!