My Project
intrusive_ptr.h
1 #pragma once
2 //-----------------------------------------------------------------------------
3 // Class: Intrusive_ptr
4 // Authors: LiXizhi
5 // Emails: LiXizhi@yeah.net
6 // Company: ParaEngine
7 // Date: 2009.6.4
8 // Desc: a thread-safe intrusive_ptr to replace boost::shared_ptr. It has smaller memory footprint than shared_ptr.
9 // since the reference counter is on the object itself.
10 //-----------------------------------------------------------------------------
11 namespace ParaEngine
12 {
13  class intrusive_ptr_thread_safe_base;
14  class intrusive_ptr_single_thread_base;
15 }
16 
17 namespace boost
18 {
19  // the two function overloads must be in the boost namespace on most compilers:
20  PE_CORE_DECL void intrusive_ptr_add_ref(ParaEngine::intrusive_ptr_thread_safe_base* ref);
21  PE_CORE_DECL void intrusive_ptr_release(ParaEngine::intrusive_ptr_thread_safe_base* ref);
22 
23  PE_CORE_DECL void intrusive_ptr_add_ref(ParaEngine::intrusive_ptr_single_thread_base* ref);
24  PE_CORE_DECL void intrusive_ptr_release(ParaEngine::intrusive_ptr_single_thread_base* ref);
25 }
26 
27 #include <boost/intrusive_ptr.hpp>
28 #include <boost/detail/atomic_count.hpp>
29 
30 #ifndef ParaIntrusivePtr
31 #define ParaIntrusivePtr boost::intrusive_ptr
32 #endif
33 
34 namespace ParaEngine
35 {
47  class PE_CORE_DECL intrusive_ptr_thread_safe_base
48  {
49  friend void boost::intrusive_ptr_add_ref(intrusive_ptr_thread_safe_base*);
50  friend void boost::intrusive_ptr_release(intrusive_ptr_thread_safe_base*);
51  public:
52 #ifdef WIN32
53  mutable long m_ref_count;
54 #else
55  mutable boost::detail::atomic_count m_ref_count;
56 #endif
57  protected:
58  intrusive_ptr_thread_safe_base() : m_ref_count(0){};
60  intrusive_ptr_thread_safe_base& operator=(const intrusive_ptr_thread_safe_base&) { return *this; }
61  virtual ~intrusive_ptr_thread_safe_base(){};
62  };
63 
76  {
77  friend void boost::intrusive_ptr_add_ref(intrusive_ptr_single_thread_base*);
78  friend void boost::intrusive_ptr_release(intrusive_ptr_single_thread_base*);
79 
80  public:
81  mutable long m_ref_count;
82 
83  protected:
84  intrusive_ptr_single_thread_base() : m_ref_count(0){};
86  intrusive_ptr_single_thread_base& operator=(const intrusive_ptr_single_thread_base&) { return *this; }
88  };
89 }
Definition: basic_dir_monitor.hpp:13
different physics engine has different winding order.
Definition: EventBinding.h:32
multi-threaded reference counted base class for boost::intrusive_ptr all boost::intrusive_ptr<T>, should derive from this class.
Definition: intrusive_ptr.h:47
single-threaded reference counted base class for boost::intrusive_ptr all boost::intrusive_ptr<T>, should derive from this class.
Definition: intrusive_ptr.h:75