Gnash
0.8.11dev
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
libbase
ref_counted.h
Go to the documentation of this file.
1
//
2
// Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3
// Free Software Foundation, Inc
4
//
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.
9
//
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.
14
//
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
18
19
#ifndef GNASH_REF_COUNTED_H
20
#define GNASH_REF_COUNTED_H
21
22
#include "
dsodefs.h
"
// for DSOEXPORT
23
24
#include <cassert>
25
#include <boost/detail/atomic_count.hpp>
26
27
namespace
gnash {
28
34
class
DSOEXPORT
ref_counted
35
{
36
37
private
:
38
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)
43
//
44
typedef
boost::detail::atomic_count Counter;
45
46
mutable
Counter m_ref_count;
47
48
protected
:
49
50
// A ref-counted object only deletes self,
51
// must never be explicitly deleted !
52
virtual
~ref_counted
()
53
{
54
assert
(m_ref_count == 0);
55
}
56
57
public
:
58
ref_counted
()
59
:
60
m_ref_count(0)
61
{
62
}
63
64
ref_counted
(
const
ref_counted
&)
65
:
66
m_ref_count(0)
67
{
68
}
69
70
void
add_ref
()
const
{
71
assert
(m_ref_count >= 0);
72
++m_ref_count;
73
}
74
75
void
drop_ref
()
const
{
76
77
assert
(m_ref_count > 0);
78
if
(!--m_ref_count) {
79
// Delete me!
80
delete
this
;
81
}
82
}
83
84
long
get_ref_count
()
const
{
return
m_ref_count; }
85
};
86
87
inline
void
88
intrusive_ptr_add_ref
(
const
ref_counted
*
o
)
89
{
90
o->
add_ref
();
91
}
92
93
inline
void
94
intrusive_ptr_release
(
const
ref_counted
*
o
)
95
{
96
o->
drop_ref
();
97
}
98
99
}
// namespace gnash
100
101
#endif // GNASH_REF_COUNTED_H
Generated on Tue Jan 28 2014 17:18:08 for Gnash by
1.8.4