1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Brian Aker
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions are met:
9
* * Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* * Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
* * Neither the name of the <organization> nor the
15
* names of its contributors may be used to endorse or promote products
16
* derived from this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
22
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
I've looked at a number of examples on the web, this is a composite of what I have seen/liked.
36
#include <boost/checked_delete.hpp>
37
#include <boost/detail/atomic_count.hpp>
38
#include <boost/intrusive_ptr.hpp>
39
#include <boost/thread.hpp>
41
#ifndef DRIZZLED_UTIL_INTRUSIVE_BASE_PTR_H
42
#define DRIZZLED_UTIL_INTRUSIVE_BASE_PTR_H
48
class intrusive_ptr_base
56
intrusive_ptr_base(intrusive_ptr_base<T> const&) :
61
intrusive_ptr_base& operator=(intrusive_ptr_base const& rhs)
66
friend void intrusive_ptr_add_ref(intrusive_ptr_base<T> const* s)
68
assert(s->_reference_count >= 0);
70
++s->_reference_count;
73
friend void intrusive_ptr_release(intrusive_ptr_base<T> const* s)
75
assert(s->_reference_count > 0);
78
if (--s->_reference_count == 0)
79
boost::checked_delete(static_cast<T const*>(s));
82
boost::intrusive_ptr<T> self()
84
return boost::intrusive_ptr<T>((T*)this);
87
boost::intrusive_ptr<const T> self() const
89
return boost::intrusive_ptr<const T>((T const*)this);
94
return _reference_count == 0;
99
return _reference_count;
103
mutable boost::detail::atomic_count _reference_count;
107
} // namespace drizzled
109
#endif /* DRIZZLED_UTIL_INTRUSIVE_BASE_PTR_H */