Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

ref_count_base.hpp
Go to the documentation of this file.
1 //
2 // immer: immutable data structures for C++
3 // Copyright (C) 2016, 2017, 2018 Juan Pedro Bolivar Puente
4 //
5 // This software is distributed under the Boost Software License, Version 1.0.
6 // See accompanying file LICENSE or copy at http://boost.org/LICENSE_1_0.txt
7 //
8 
9 #pragma once
10 
11 #include <atomic>
12 
13 namespace immer {
14 namespace detail {
15 
16 template <typename Deriv>
18 {
19  mutable std::atomic<int> ref_count { 0 };
20 
21  friend void intrusive_ptr_add_ref(const Deriv* x)
22  {
23  x->ref_count.fetch_add(1, std::memory_order_relaxed);
24  }
25 
26  friend void intrusive_ptr_release(const Deriv* x)
27  {
28  if (x->ref_count.fetch_sub(1, std::memory_order_release) == 1) {
29  std::atomic_thread_fence(std::memory_order_acquire);
30  delete x;
31  }
32  }
33 };
34 
35 } /* namespace detail */
36 } /* namespace immer */
friend void intrusive_ptr_add_ref(const Deriv *x)
friend void intrusive_ptr_release(const Deriv *x)
Released under the MIT license