mCRL2
Loading...
Searching...
No Matches
aterm_implementation.cpp
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#include "mcrl2/atermpp/aterm_io.h"
11#include "mcrl2/atermpp/detail/global_aterm_pool.h"
12#include "mcrl2/utilities/shared_mutex.h"
13
14#include <array>
15
16using namespace atermpp;
17using namespace atermpp::detail;
18
19/// \brief Check for reasonably sized aterm (32 bits, 4 bytes)
20/// This check might break on perfectly valid architectures
21/// that have char == 2 bytes, and sizeof(header_type) == 2
22static_assert(sizeof(std::size_t) == sizeof(_aterm*), "The size of an aterm pointer is not equal to the size of type std::size_t. Cannot compile the MCRL2 toolset for this platform.");
23static_assert(sizeof(std::size_t) >= 4,"The size of std::size_t should at least be four bytes. Cannot compile the toolset for this platform.");
24
25void atermpp::add_deletion_hook(const function_symbol& function, term_callback callback)
26{
27 g_term_pool().add_deletion_hook(function, callback);
28}
29
30namespace atermpp::detail
31{
32
33// Pointer to the main thread's pool. Set once, on the first call to
34// g_thread_term_pool() (which is always from the main thread in practice).
35// Used by ~thread_aterm_pool to transfer orphaned entries when a worker
36// thread exits.
38
39/// \brief A reference to the thread local term pool storage
41{
42#ifdef MCRL2_ENABLE_MULTITHREADING
43 static_assert(mcrl2::utilities::detail::GlobalThreadSafe);
44 thread_local thread_aterm_pool instance(g_aterm_pool_instance());
45#else
46 static_assert(!mcrl2::utilities::detail::GlobalThreadSafe);
48#endif
49 // Record the main-thread pool on first call. This is always safe: the
50 // main thread initialises its pool before spawning any worker threads.
51 if (g_main_thread_pool == nullptr)
52 {
53 g_main_thread_pool = &instance;
54 }
55 return instance;
56}
57
58mcrl2::utilities::shared_guard lock_shared_aterm_pool()
59{
60 return g_thread_term_pool().lock_shared();
61}
62
63} // end namespace atermpp::detail
64
65aterm_stream::~aterm_stream() = default;
66
67aterm_istream::~aterm_istream() = default;
68
69aterm_ostream::~aterm_ostream() = default;
70
71/// Definition of the extern global term pool.
72alignas(aterm_pool)
The interface for a class that reads aterm from a stream. The default constructed term aterm() indica...
Definition aterm_io.h:62
The interface for a class that writes aterm to a stream. Every written term is retrieved by the corre...
Definition aterm_io.h:51
The general aterm stream interface, which enables the use of a transformer to change the written/read...
Definition aterm_io.h:34
thread_aterm_pool(aterm_pool &global_pool)
std::stack< std::reference_wrapper< _aterm > > m_todo
A reusable todo stack.
A unordered_map class in which aterms can be stored.
thread_aterm_pool & g_thread_term_pool()
A reference to the thread local term pool storage.
aterm_pool & g_aterm_pool_instance()
A reference to the global term pool storage.
thread_aterm_pool * g_main_thread_pool
Pointer to the main thread's pool; set on its first access and used by ~thread_aterm_pool to transfer...
mcrl2::utilities::shared_guard lock_shared_aterm_pool()
Acquires a shared lock on the global thread aterm pool.
std::array< std::byte, sizeof(aterm_pool)> g_aterm_pool_storage
Storage for a global term pool that is not initialized.
The main namespace for the aterm++ library.
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...