mCRL2
Loading...
Searching...
No Matches
aterm_implementation.h
Go to the documentation of this file.
1// Author(s): Maurice Laveaux.
2// Copyright: see the accompanying file COPYING or copy at
3// https://github.com/mCRL2org/mCRL2/blob/master/COPYING
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
9
10#ifndef MCRL2_ATERMPP_ATERM_IMPLEMENTATION_H
11#define MCRL2_ATERMPP_ATERM_IMPLEMENTATION_H
12#pragma once
13
16
17namespace atermpp
18{
19
20namespace detail
21{
22 template<typename T>
23 const reference_aterm<T, typename std::enable_if_t<std::is_base_of<aterm, T>::value>>&
24 reference_aterm<T, typename std::enable_if_t<std::is_base_of<aterm, T>::value>>::operator=(const unprotected_aterm& other) noexcept
25 {
27 m_term = address(other);
28 return *this;
29 }
30
31 template<typename T>
32 const reference_aterm<T, typename std::enable_if_t<std::is_base_of<aterm, T>::value>>&
33 reference_aterm<T, typename std::enable_if_t<std::is_base_of<aterm, T>::value>>::operator=(unprotected_aterm&& other) noexcept
34 {
36 m_term = address(other);
37 return *this;
38 }
39
40 template<typename T, typename Allocator>
42 {
44 m_allocator.deallocate(p, n);
45 }
46
47 inline
48 aterm_container::aterm_container(std::function<void(term_mark_stack&)> mark_func, std::function<std::size_t()> size_func)
49 : mark_func(mark_func),
50 size_func(size_func)
51 {
53 }
54
55 inline
57 {
59 }
60}
61
62inline aterm::aterm() noexcept
63{
65}
66
67inline aterm::~aterm() noexcept
68{
70}
71
72inline aterm::aterm(const detail::_aterm *t) noexcept
73{
75 m_term = t;
76}
77
78inline aterm::aterm(const aterm& other) noexcept
79 : unprotected_aterm(other.m_term)
80{
82}
83
84inline aterm::aterm(aterm&& other) noexcept
85 : unprotected_aterm(other.m_term)
86{
88}
89
90inline aterm& aterm::operator=(const aterm& other) noexcept
91{
93 m_term = other.m_term;
94 return *this;
95}
96
97inline aterm& aterm::assign(const aterm& other,
99{
100 mcrl2::utilities::shared_guard guard = pool.lock_shared();
101 m_term = other.m_term;
102 return *this;
103}
104
105
106template <bool CHECK_BUSY_FLAG /* =true*/>
107inline aterm& aterm::unprotected_assign(const aterm& other) noexcept
108{
110 m_term = other.m_term;
111 return *this;
112}
113
114
115inline aterm& aterm::operator=(aterm&& other) noexcept
116{
118 // Using hash set protection it is cheaper just to move the value to the new term.
119 m_term = other.m_term;
120 return *this;
121}
122
123
124} // namespace atermpp
125
126#endif // MCRL2_ATERMPP_TERM_IMPLEMENTATION_H
The aterm base class that provides protection of the underlying shared terms.
Definition aterm.h:186
aterm() noexcept
Default constructor.
aterm & operator=(const aterm &other) noexcept
Assignment operator.
aterm & assign(const aterm &other, detail::thread_aterm_pool &pool) noexcept
Assignment operator, to be used if busy and forbidden flags are explicitly available.
aterm & unprotected_assign(const aterm &other) noexcept
Assignment operator, to be used when the busy flags do not need to be set.
~aterm() noexcept
Standard destructor.
This is the class to which an aterm points.
Definition aterm.h:48
aterm_container(std::function< void(term_mark_stack &)> mark_func, std::function< std::size_t()> size_func)
This is a thread's specific access to the global aterm pool which ensures that garbage collection and...
void deregister_container(aterm_container *variable)
Removes the given container from the active variables.
void register_container(aterm_container *variable)
Consider the given container when marking underlying terms.
void register_variable(aterm *variable)
Consider the given variable when marking underlying terms.
bool is_shared_locked()
Returns true iff we are in a shared section.
void deregister_variable(aterm *variable)
Removes the given variable from the active variables.
mcrl2::utilities::shared_guard lock_shared()
Acquire a shared lock on this thread aterm pool.
An unprotected term does not change the reference count of the shared term when it is copied or moved...
Definition aterm.h:36
const detail::_aterm * m_term
Definition aterm.h:40
A shared lock guard for the shared_mutex.
a pool allocator class
thread_aterm_pool & g_thread_term_pool()
A reference to the thread local term pool storage.
_aterm * address(const unprotected_aterm &t)
Definition aterm.h:347
The main namespace for the aterm++ library.
Definition algorithm.h:21
std::stack< std::reference_wrapper< detail::_aterm > > term_mark_stack
static constexpr bool GlobalThreadSafe
Enables thread safety for the whole toolset.