2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef GNASH_REF_COUNTED_H
20 #define GNASH_REF_COUNTED_H
22 #include "dsodefs.h" // for DSOEXPORT
25 #include <boost/detail/atomic_count.hpp>
30 /// For stuff that's tricky to keep track of w/r/t ownership & cleanup.
31 /// The only use for this class seems to be for putting derived
32 /// classes in smart_ptr
34 class DSOEXPORT ref_counted
39 // We use an atomic counter to make ref-counting
40 // thread-safe. The drop_ref() method must be
41 // carefully designed for this to be effective
42 // (decrement & check in a single statement)
44 typedef boost::detail::atomic_count Counter
;
46 mutable Counter m_ref_count
;
50 // A ref-counted object only deletes self,
51 // must never be explicitly deleted !
52 virtual ~ref_counted()
54 assert(m_ref_count
== 0);
64 ref_counted(const ref_counted
&)
70 void add_ref() const {
71 assert(m_ref_count
>= 0);
75 void drop_ref() const {
77 assert(m_ref_count
> 0);
84 long get_ref_count() const { return m_ref_count
; }
89 #endif // GNASH_REF_COUNTED_H