10#ifndef MCRL2_UTILITIES_SHARED_REFERENCE_H_
11#define MCRL2_UTILITIES_SHARED_REFERENCE_H_
19#include "mcrl2/utilities/tagged_pointer.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;
aterm create_nested_function(const std::string &function_name, const std::string &leaf_name, std::size_t depth)
Create a nested function application f_depth. Where f_0 = c and f_i = f(f_i-1,...,...
aterm create_nested_function(const std::string &function_name, const std::string &leaf_name, std::size_t number_of_arguments, std::size_t depth)
Create a nested function application f_depth. Where f_0 = c and f_i = f(f_i-1,...,...
void benchmark_threads(std::size_t number_of_threads, F f)
The aterm_core base class that provides protection of the underlying shared terms.
aterm_core & operator=(aterm_core &&other) noexcept
Move assignment operator.
~aterm_core() noexcept
Standard destructor.
aterm_core & operator=(const aterm_core &other) noexcept
Assignment operator.
aterm_core(const aterm_core &other) noexcept
Copy constructor.
aterm_core(aterm_core &&other) noexcept
Move constructor.
aterm_core() noexcept
Default constructor.
aterm_core & assign(const aterm_core &other, detail::thread_aterm_pool &pool) noexcept
Assignment operator, to be used if busy and forbidden flags are explicitly available.
aterm_core & unprotected_assign(const aterm_core &other) noexcept
Assignment operator, to be used when the busy flags do not need to be set.
aterm_core(const detail::_aterm *t) noexcept
Constructor based on an internal term data structure. This is not for public use.
aterm(aterm &&other) noexcept=default
aterm(const function_symbol &sym, InputIterator begin, InputIterator end, TermConverter converter)
const_iterator end() const
Returns a const_iterator pointing past the last argument.
aterm(const function_symbol &symbol, const Terms &...arguments)
Constructor for n-arity function application.
const aterm & operator[](const size_type i) const
Returns the i-th argument.
aterm()
Default constructor.
const_iterator begin() const
Returns an iterator pointing to the first argument.
aterm(const function_symbol &sym, InputIterator begin, InputIterator end)
Constructor that provides an aterm based on a function symbol and an input iterator providing the arg...
aterm(const function_symbol &sym, ForwardIterator begin, ForwardIterator end)
Constructor that provides an aterm based on a function symbol and forward iterator providing the argu...
aterm & operator=(const aterm &other) noexcept=default
const function_symbol & function() const
Returns the function symbol belonging to an aterm.
std::size_t size_type
An unsigned integral type.
aterm(const aterm &other) noexcept=default
This class has user-declared copy constructor so declare default copy and move operators.
aterm(detail::_term_appl *t)
Constructor.
ptrdiff_t difference_type
A signed integral type.
bool empty() const
Returns true if the term has no arguments.
aterm & operator=(aterm &&other) noexcept=default
aterm(const function_symbol &sym)
Constructor.
term_appl_iterator< aterm > iterator
Iterator used to iterate through an term_appl.
size_type size() const
Returns the number of arguments of this term.
term_appl_iterator< aterm > const_iterator
Const iterator used to iterate through an term_appl.
constexpr size_type max_size() const
Returns the largest possible number of arguments.
This is the class to which an aterm points.
bool is_marked() const
Check if the term is already marked.
_aterm(const function_symbol &symbol)
Create a term from a function symbol.
function_symbol m_function_symbol
const function_symbol & function() const noexcept
void mark() const
Mark this term to be garbage collected.
void unmark() const
Remove the mark from a term.
Stores the data for a function symbol (name, arity) pair.
const std::size_t m_arity
const std::string & name() const noexcept
bool operator==(const _function_symbol &f) const noexcept
std::size_t arity() const noexcept
void enable_garbage_collection(bool enable)
Enable garbage collection when passing true and disable otherwise.
This class stores a set of function symbols.
void create_term(aterm &term, const function_symbol &sym)
Generates unique function symbols with a given prefix.
bool operator!=(const function_symbol &f) const
Inequality test.
function_symbol & operator=(const function_symbol &other) noexcept=default
function_symbol(function_symbol &&other) noexcept=default
bool operator>=(const function_symbol &f) const
Comparison operation.
bool operator==(const function_symbol &f) const
Equality test.
function_symbol(detail::_function_symbol::ref &&f)
Constructor for internal use only.
bool operator<(const function_symbol &f) const
Comparison operation.
function_symbol(const function_symbol &other) noexcept=default
This class has non-trivial destructor so declare default copy and move operators.
void destroy()
Calls the function symbol pool to free our used memory.
void swap(function_symbol &f)
Swap this function with its argument.
function_symbol & operator=(function_symbol &&other) noexcept=default
std::size_t arity() const
Return the arity (number of arguments) of the function symbol (function_symbol).
detail::_function_symbol::ref m_function_symbol
The shared reference to the underlying function symbol.
const std::string & name() const
Return the name of the function_symbol.
bool operator>(const function_symbol &f) const
Comparison operation.
function_symbol()=default
bool operator<=(const function_symbol &f) const
Comparison operation.
An unprotected term does not change the reference count of the shared term when it is copied or moved...
bool operator<=(const unprotected_aterm_core &t) const
Comparison operator for two unprotected aterms.
bool operator>=(const unprotected_aterm_core &t) const
Comparison operator for two unprotected aterms.
bool type_is_list() const noexcept
Dynamic check whether the term is an aterm_list.
void swap(unprotected_aterm_core &t) noexcept
Swaps this term with its argument.
bool operator>(const unprotected_aterm_core &t) const
Comparison operator for two unprotected aterms.
bool operator<(const unprotected_aterm_core &t) const
Comparison operator for two unprotected aterms.
bool operator==(const unprotected_aterm_core &t) const
Comparison operator.
unprotected_aterm_core() noexcept
Default constuctor.
bool type_is_appl() const noexcept
Dynamic check whether the term is an aterm.
bool defined() const
Returns true if this term is not equal to the term assigned by the default constructor of aterms,...
friend detail::_aterm * detail::address(const unprotected_aterm_core &t)
const detail::_aterm * m_term
bool operator!=(const unprotected_aterm_core &t) const
Inequality operator on two unprotected aterms.
const function_symbol & function() const
Yields the function symbol in an aterm.
bool type_is_int() const noexcept
Dynamic check whether the term is an aterm_int.
unprotected_aterm_core(const detail::_aterm *term) noexcept
Constructor.
Inherit from this class to prevent it from being copyable.
noncopyable & operator=(const noncopyable &)=delete
noncopyable(const noncopyable &)=delete
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.
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...
Implements a simple stopwatch that starts on construction.
function_symbol g_as_empty_list
thread_aterm_pool & g_thread_term_pool()
A reference to the thread local term pool storage.
function_symbol g_as_list
function_symbol g_as_int
These function symbols are used to indicate integer, list and empty list terms.
void debug_print(std::ostream &o, const _aterm *t, const std::size_t d=3)
The main namespace for the aterm++ library.
void make_term_appl(Term &target, const function_symbol &sym, InputIterator begin, InputIterator end, TermConverter converter)
Constructor an aterm in a variable based on a function symbol and an forward iterator providing the a...
void make_term_appl(Term &target, const function_symbol &sym)
Make an term_appl consisting of a single function symbol.
Derived & reference_cast(Derived &t)
A cast from one aterm based type to another, as a reference, allowing to assign to it.
void(* term_callback)(const aterm &)
std::string pp(const atermpp::aterm &t)
Transform an aterm to an ascii string.
void make_term_appl(Term &target, const function_symbol &symbol, const Terms &...arguments)
Make an aterm application for n-arity function application.
void make_term_appl(Term &target, const function_symbol &sym, ForwardIterator begin, ForwardIterator end)
Constructor an aterm in a variable based on a function symbol and an forward iterator providing the a...
void make_term_appl(Term &target, const function_symbol &sym, InputIterator begin, InputIterator end)
Constructor an aterm in a variable based on a function symbol and an input iterator providing the arg...
void add_deletion_hook(const function_symbol &, term_callback)
Check for reasonably sized aterm (32 bits, 4 bytes) This check might break on perfectly valid archite...
const DerivedCont & container_cast(const Cont< Base > &t, typename std::enable_if_t< is_container< DerivedCont, aterm >::value &&std::is_same_v< Cont< typename DerivedCont::value_type >, DerivedCont > &&!std::is_base_of_v< DerivedCont, Cont< Base > > &&is_convertible< Base, typename DerivedCont::value_type >::value > *=nullptr)
void make_term_appl_with_index(aterm &target, const function_symbol &symbol, const Terms &...arguments)
Constructor for n-arity function application with an index.
const Derived & vertical_cast(const Base &t, typename std::enable_if< is_convertible< Base, Derived >::value >::type *=nullptr)
A cast form an aterm derived class to a class that inherits in possibly multiple steps from this clas...
const Derived & down_cast(const Base &t, typename std::enable_if< is_convertible< Base, Derived >::value &&!std::is_base_of< Derived, Base >::value >::type *=nullptr)
A cheap cast from one aterm based type to another When casting one aterm based type into another,...
const DerivedCont & vertical_cast(const Cont< Base > &t, typename std::enable_if_t< is_container< DerivedCont, aterm >::value &&std::is_same_v< Cont< typename DerivedCont::value_type >, DerivedCont > &&is_convertible< Base, typename DerivedCont::value_type >::value > *=nullptr)
Derived & reference_cast(Base &t, typename std::enable_if< is_convertible< Base, Derived >::value &&!std::is_base_of< Derived, Base >::value >::type *=nullptr)
A cast from one aterm based type to another, as a reference, allowing to assign to it.
constexpr bool is_iterable_v
static constexpr bool EnableReferenceCountMetrics
Enable to count the number of reference count changes.
constexpr bool is_iterator_v
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
void swap(atermpp::aterm &t1, atermpp::aterm &t2) noexcept
Swaps two term_applss.
void swap(mcrl2::utilities::shared_reference< T > &a, mcrl2::utilities::shared_reference< T > &b) noexcept
void swap(atermpp::unprotected_aterm_core &t1, atermpp::unprotected_aterm_core &t2) noexcept
Swaps two aterms.
int main(int argc, char *argv[])
Checks whether condition holds for all types passed as variadic template.
std::tuple_element< i, std::tuple< Args... > >::type type
A typetrait that is std::true_type iff std::begin() and std::end() can be called on type T.
A typetrait that is std::true_type iff the given type has the iterator traits.
std::size_t operator()(const atermpp::aterm &t) const
std::size_t operator()(const atermpp::aterm_core &t) const
std::size_t operator()(const atermpp::detail::reference_aterm< T > &t) const