CppCMS
sp_counted_base.h
1 #ifndef BOOSTER_SMART_PTR_DETAIL_SP_COUNTED_BASE_SPIN_HPP_INCLUDED
2 #define BOOSTER_SMART_PTR_DETAIL_SP_COUNTED_BASE_SPIN_HPP_INCLUDED
3 
4 //
5 // detail/sp_counted_base_spin.hpp - spinlock pool atomic emulation
6 //
7 // Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
8 // Copyright 2004-2008 Peter Dimov
9 //
10 // Distributed under the Boost Software License, Version 1.0. (See
11 // accompanying file LICENSE_1_0.txt or copy at
12 // http://www.boost.org/LICENSE_1_0.txt)
13 //
14 
15 #include <booster/config.h>
16 #include <booster/smart_ptr/sp_typeinfo.h>
17 
18 #ifndef BOOSTER_WIN32
19 #include <pthread.h>
20 #endif
21 
22 namespace booster
23 {
24 
25  namespace detail
26  {
27 
28  typedef union sp_counted_base_atomic {
29  int i;
30  unsigned int ui;
31  long int li;
32  unsigned long int uli;
33  long long int lli;
34  unsigned long long int ulli;
35  char at_least[8];
37 
38 
39  class BOOSTER_API sp_counted_base
40  {
41  private:
42 
44  sp_counted_base & operator= ( sp_counted_base const & );
45 
47 
48  mutable atomic_type use_count_; // #shared
49  mutable atomic_type weak_count_; // #weak + (#shared != 0)
50 #ifndef BOOSTER_WIN32
51  mutable pthread_mutex_t lock_;
52 #endif
53 
54  public:
55 
57  virtual ~sp_counted_base(); // nothrow
58 
59  // dispose() is called when use_count_ drops to zero, to release
60  // the resources managed by *this.
61 
62  virtual void dispose() = 0; // nothrow
63 
64  // destroy() is called when weak_count_ drops to zero.
65 
66  virtual void destroy(); // nothrow
67  virtual void * get_deleter( sp_typeinfo const & ti ) = 0;
68  void add_ref_copy();
69  bool add_ref_lock(); // true on success
70  void release(); // nothrow
71  void weak_add_ref(); // nothrow
72  void weak_release(); // nothrow
73  long use_count() const; // nothrow
74  };
75 
76  } // namespace detail
77 
78 } // namespace boost
79 
80 #endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_BASE_SPIN_HPP_INCLUDED
81 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
Definition: sp_counted_base.h:39
Definition: sp_counted_base.h:28
Booster library namespace. The library that implements Boost Like API in ABI backward compatible way...
Definition: application.h:23