Qore Programming Language 0.8.8

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
QoreReferenceCounter.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3 QoreReferenceCounter.h
4
5 Qore Programming Language
6
7 Copyright (C) 2003 - 2013 David Nichols, all rights reserved
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 #ifndef _QORE_QOREREFERENCECOUNTER_H
25
26 #define _QORE_QOREREFERENCECOUNTER_H
27
28 #include <qore/common.h>
29 #include <qore/macros.h>
30
31 class QoreThreadLock;
32
34 class QoreReferenceCounter {
35 protected:
36 mutable int references;
37 #ifndef HAVE_ATOMIC_MACROS
38 mutable QoreThreadLock mRO;
40 #endif
41
42 public:
44 DLLEXPORT QoreReferenceCounter();
45
47 DLLEXPORT ~QoreReferenceCounter();
48
50
53 DLLLOCAL int reference_count() const {
54 return references;
55 }
56
58
61 DLLLOCAL bool is_unique() const {
62 return references == 1;
63 }
64
66 DLLEXPORT void ROreference() const;
67
69
73 DLLEXPORT bool ROdereference() const;
74 };
75
76 #endif // _QORE_QOREREFERENCECOUNTER_H
QoreReferenceCounter::ROdereference
DLLEXPORT bool ROdereference() const
atomically decrements the reference count
QoreReferenceCounter::mRO
QoreThreadLock mRO
pthread lock to ensure atomicity of updates for architectures where we don&#39;t have an atomic increment...
Definition: QoreReferenceCounter.h:39
QoreReferenceCounter::ROreference
DLLEXPORT void ROreference() const
atomically increments the reference count
QoreReferenceCounter::reference_count
DLLLOCAL int reference_count() const
gets the reference count
Definition: QoreReferenceCounter.h:53
QoreReferenceCounter
provides atomic reference counting to Qore objects
Definition: QoreReferenceCounter.h:34
QoreReferenceCounter::is_unique
DLLLOCAL bool is_unique() const
returns true if the reference count is 1
Definition: QoreReferenceCounter.h:61
common.h
QoreThreadLock
provides a mutually-exclusive thread lock
Definition: QoreThreadLock.h:41
QoreReferenceCounter::~QoreReferenceCounter
DLLEXPORT ~QoreReferenceCounter()
destroys the reference counter object
QoreReferenceCounter::QoreReferenceCounter
DLLEXPORT QoreReferenceCounter()
creates the reference counter object