CppCMS
refcounted.h
1 //
3 // Copyright (C) 2008-2012 Artyom Beilis (Tonkikh)
4 //
5 // Distributed under the Boost Software License, Version 1.0. (See
6 // accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 //
9 #ifndef BOOSTER_REFCOUNTED_H
10 #define BOOSTER_REFCOUNTED_H
11 
12 #include <booster/atomic_counter.h>
13 
14 namespace booster {
15 
16  class refcounted;
17  void intrusive_ptr_add_ref(refcounted *ptr);
18  void intrusive_ptr_release(refcounted *ptr);
19 
25  class refcounted {
26  public:
27  refcounted() :
28  refs_(0)
29  {
30  }
31 
32  virtual ~refcounted()
33  {
34  }
35 
36  private:
37  friend void intrusive_ptr_add_ref(refcounted *);
38  friend void intrusive_ptr_release(refcounted *);
39 
40  refcounted(refcounted const &other);
41  refcounted const &operator=(refcounted const &other);
42  atomic_counter refs_;
43  };
44 
49  {
50  ++p->refs_;
51  }
56  {
57  if(p && --p->refs_ == 0)
58  delete p;
59  }
60 
61 }
62 
63 
64 #endif
This class is used as base class for reference counted objects that use intrusive_ptr. Deriving from this class allows simple way to manage reference counting for single object.
Definition: refcounted.h:25
friend void intrusive_ptr_release(refcounted *)
Definition: refcounted.h:55
friend void intrusive_ptr_add_ref(refcounted *)
Definition: refcounted.h:48
Booster library namespace. The library that implements Boost Like API in ABI backward compatible way...
Definition: application.h:23
Atomic counter is a class that allows perform counting in thread safe way.
Definition: atomic_counter.h:33