LCOV - code coverage report
Current view: top level - atermpp/include/mcrl2/atermpp/detail - aterm_implementation.h (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 45 45 100.0 %
Date: 2024-05-04 03:44:52 Functions: 15 15 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
      14             : #include "mcrl2/atermpp/detail/global_aterm_pool.h"
      15             : #include "mcrl2/atermpp/detail/aterm_container.h"
      16             : 
      17             : namespace atermpp
      18             : {
      19             : 
      20             : namespace detail
      21             : {
      22             :   template<typename T>
      23             :   const reference_aterm<T, typename std::enable_if_t<std::is_base_of<aterm, T>::value>>&
      24       18615 :     reference_aterm<T, typename std::enable_if_t<std::is_base_of<aterm, T>::value>>::operator=(const unprotected_aterm& other) noexcept
      25             :   {
      26       18615 :     mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
      27       18615 :     m_term = address(other);
      28       37230 :     return *this;
      29       18615 :   }
      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             :   {
      35             :     mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
      36             :     m_term = address(other);
      37             :     return *this;
      38             :   }
      39             : 
      40             :   template<typename T, typename Allocator>
      41             :   void aterm_allocator<T,Allocator>::deallocate(T* p, size_type n)
      42             :   {
      43             :     mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
      44             :     m_allocator.deallocate(p, n);
      45             :   }
      46             : 
      47             :   inline
      48       52057 :   aterm_container::aterm_container(std::function<void(term_mark_stack&)> mark_func, std::function<std::size_t()> size_func)
      49       52057 :     : mark_func(mark_func),
      50       52057 :       size_func(size_func)
      51             :   {
      52       52057 :     g_thread_term_pool().register_container(this);
      53       52057 :   }
      54             : 
      55             :   inline
      56       52057 :   aterm_container::~aterm_container()
      57             :   {
      58       52057 :     g_thread_term_pool().deregister_container(this);
      59       52057 :   }
      60             : }
      61             : 
      62 10680816637 : inline aterm::aterm() noexcept
      63             : {
      64 10680816637 :   detail::g_thread_term_pool().register_variable(this);
      65 10680816637 : }
      66             : 
      67 21756366559 : inline aterm::~aterm() noexcept
      68             : {
      69 21756366559 :   detail::g_thread_term_pool().deregister_variable(this);
      70 21756366559 : }
      71             : 
      72             : inline aterm::aterm(const detail::_aterm *t) noexcept
      73             : {
      74             :   detail::g_thread_term_pool().register_variable(this);
      75             :   m_term = t;
      76             : }
      77             : 
      78 10928463095 : inline aterm::aterm(const aterm& other) noexcept
      79 10928463095 :  : unprotected_aterm(other.m_term)
      80             : {
      81 10928463095 :   detail::g_thread_term_pool().register_variable(this);
      82 10928463095 : }
      83             : 
      84   147129447 : inline aterm::aterm(aterm&& other) noexcept
      85   147129447 :  : unprotected_aterm(other.m_term)
      86             : {
      87   147129447 :   detail::g_thread_term_pool().register_variable(this);
      88   147129447 : }
      89             : 
      90    18397486 : inline aterm& aterm::operator=(const aterm& other) noexcept
      91             : {
      92    18397486 :   mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
      93    18397486 :   m_term = other.m_term;
      94    36794972 :   return *this;
      95    18397486 : }
      96             : 
      97     2125486 : inline aterm& aterm::assign(const aterm& other,
      98             :   detail::thread_aterm_pool& pool) noexcept
      99             : {
     100     2125486 :   mcrl2::utilities::shared_guard guard = pool.lock_shared();
     101     2125486 :   m_term = other.m_term;
     102     4250972 :   return *this;
     103     2125486 : }
     104             : 
     105             : 
     106             : template <bool CHECK_BUSY_FLAG /* =true*/>
     107       26516 : inline aterm& aterm::unprotected_assign(const aterm& other) noexcept
     108             : {
     109             :   if constexpr (mcrl2::utilities::detail::GlobalThreadSafe && CHECK_BUSY_FLAG) assert(detail::g_thread_term_pool().is_shared_locked());
     110       26516 :   m_term = other.m_term;
     111       26516 :   return *this;
     112             : }
     113             : 
     114             : 
     115    48601374 : inline aterm& aterm::operator=(aterm&& other) noexcept
     116             : {
     117    48601374 :   mcrl2::utilities::shared_guard guard = detail::g_thread_term_pool().lock_shared();
     118             :   // Using hash set protection it is cheaper just to move the value to the new term.
     119    48601374 :   m_term = other.m_term;    
     120    97202748 :   return *this;
     121    48601374 : }
     122             : 
     123             : 
     124             : } // namespace atermpp
     125             : 
     126             : #endif // MCRL2_ATERMPP_TERM_IMPLEMENTATION_H

Generated by: LCOV version 1.14