10#ifndef MCRL2_UTILITIES_SHARED_REFERENCE_H_
11#define MCRL2_UTILITIES_SHARED_REFERENCE_H_
32template<
typename T,
bool ThreadSafe = false>
49 if constexpr (ThreadSafe)
63 if constexpr (ThreadSafe)
77 static std::atomic<std::size_t> g_reference_count_changes;
78 return g_reference_count_changes;
91 using SizeType =
typename std::conditional<ThreadSafe, std::atomic<std::size_t>, std::size_t>::type;
134 other.m_reference =
nullptr;
151 other.m_reference->increment_reference_count();
173 other.m_reference =
nullptr;
Stores a reference count that can be incremented and decremented.
SizeType m_reference_count
static void count_reference_count_changes()
Increment the number of reference count changes.
typename std::conditional< ThreadSafe, std::atomic< std::size_t >, std::size_t >::type SizeType
shared_reference_counted()
std::size_t reference_count() const
Obtain the reference count.
void increment_reference_count() const
Increment the reference count by one.
static std::atomic< std::size_t > & reference_count_changes()
Obtain the number of times that this reference count has changed.
void decrement_reference_count() const
Decrement the reference count by one.
A reference counted reference to a shared_reference_counted object.
bool operator==(const shared_reference< T > &other) const noexcept
bool operator>=(const shared_reference &other) const noexcept
shared_reference< T > & operator=(shared_reference< T > &&other) noexcept
Move assignment constructor.
T * operator->() const noexcept
bool defined() const
Check whether the shared_reference has a valid reference.
bool operator>(const shared_reference< T > &other) const noexcept
T & operator*() const noexcept
bool tagged() const noexcept
shared_reference() noexcept
The default constructor.
void swap(shared_reference< T > &other)
Swaps *this with the other shared reference.
utilities::tagged_pointer< T > m_reference
shared_reference< T > & operator=(const shared_reference< T > &other) noexcept
Copy assignment constructor.
bool operator!=(const shared_reference< T > &other) const noexcept
bool operator<=(const shared_reference< T > &other) const noexcept
shared_reference(shared_reference< T > &&other) noexcept
Move constructor.
shared_reference(const shared_reference< T > &other) noexcept
Copy constructor.
bool operator<(const shared_reference< T > &other) const noexcept
shared_reference(T *reference) noexcept
Takes ownership of the passed reference, which means that its reference count is incremented.
A pointer storage object that uses a least significant bit as a mark. Can be used by objects that are...
static constexpr bool EnableReferenceCountMetrics
Enable to count the number of reference count changes.
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
void swap(atermpp::unprotected_aterm_core &t1, atermpp::unprotected_aterm_core &t2) noexcept
Swaps two aterms.