mirror of
https://github.com/TomHarte/CLK.git
synced 2024-09-30 07:55:01 +00:00
Add attempt to detect improper usage.
This commit is contained in:
parent
5c7367b262
commit
f38cf91ea7
@ -14,6 +14,8 @@
|
|||||||
#include "ClockingHintSource.hpp"
|
#include "ClockingHintSource.hpp"
|
||||||
#include "ForceInline.hpp"
|
#include "ForceInline.hpp"
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
A JustInTimeActor holds (i) an embedded object with a run_for method; and (ii) an amount
|
A JustInTimeActor holds (i) an embedded object with a run_for method; and (ii) an amount
|
||||||
of time since run_for was last called.
|
of time since run_for was last called.
|
||||||
@ -121,7 +123,13 @@ template <class T, class LocalTimeScale = HalfCycles, int multiplier = 1, int di
|
|||||||
/// If this object provides sequence points, checks for changes to the next
|
/// If this object provides sequence points, checks for changes to the next
|
||||||
/// sequence point upon deletion of the pointer.
|
/// sequence point upon deletion of the pointer.
|
||||||
[[nodiscard]] forceinline auto operator->() {
|
[[nodiscard]] forceinline auto operator->() {
|
||||||
|
#ifndef NDEBUG
|
||||||
|
assert(!flush_concurrency_check_.test_and_set());
|
||||||
|
#endif
|
||||||
flush();
|
flush();
|
||||||
|
#ifndef NDEBUG
|
||||||
|
flush_concurrency_check_.clear();
|
||||||
|
#endif
|
||||||
return std::unique_ptr<T, SequencePointAwareDeleter>(&object_, SequencePointAwareDeleter(this));
|
return std::unique_ptr<T, SequencePointAwareDeleter>(&object_, SequencePointAwareDeleter(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +138,13 @@ template <class T, class LocalTimeScale = HalfCycles, int multiplier = 1, int di
|
|||||||
/// Despite being const, this will flush the object and, if relevant, update the next sequence point.
|
/// Despite being const, this will flush the object and, if relevant, update the next sequence point.
|
||||||
[[nodiscard]] forceinline auto operator -> () const {
|
[[nodiscard]] forceinline auto operator -> () const {
|
||||||
auto non_const_this = const_cast<JustInTimeActor<T, LocalTimeScale, multiplier, divider> *>(this);
|
auto non_const_this = const_cast<JustInTimeActor<T, LocalTimeScale, multiplier, divider> *>(this);
|
||||||
|
#ifndef NDEBUG
|
||||||
|
assert(!non_const_this->flush_concurrency_check_.test_and_set());
|
||||||
|
#endif
|
||||||
non_const_this->flush();
|
non_const_this->flush();
|
||||||
|
#ifndef NDEBUG
|
||||||
|
non_const_this->flush_concurrency_check_.clear();
|
||||||
|
#endif
|
||||||
return std::unique_ptr<const T, SequencePointAwareDeleter>(&object_, SequencePointAwareDeleter(non_const_this));
|
return std::unique_ptr<const T, SequencePointAwareDeleter>(&object_, SequencePointAwareDeleter(non_const_this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,6 +278,10 @@ template <class T, class LocalTimeScale = HalfCycles, int multiplier = 1, int di
|
|||||||
void set_component_prefers_clocking(ClockingHint::Source *, ClockingHint::Preference clocking) {
|
void set_component_prefers_clocking(ClockingHint::Source *, ClockingHint::Preference clocking) {
|
||||||
clocking_preference_ = clocking;
|
clocking_preference_ = clocking;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
std::atomic_flag flush_concurrency_check_{};
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
Loading…
Reference in New Issue
Block a user