|
Qore Programming Language
0.8.3
|
00001 /* -*- mode: c++; indent-tabs-mode: nil -*- */ 00002 /* 00003 QoreReferenceCounter.h 00004 00005 Qore Programming Language 00006 00007 Copyright (C) 2003 - 2011 David Nichols, all rights reserved 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public 00020 License along with this library; if not, write to the Free Software 00021 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00022 */ 00023 00024 #ifndef _QORE_QOREREFERENCECOUNTER_H 00025 00026 #define _QORE_QOREREFERENCECOUNTER_H 00027 00028 #include <qore/common.h> 00029 #include <qore/macros.h> 00030 00031 class QoreThreadLock; 00032 00034 class QoreReferenceCounter { 00035 protected: 00036 mutable int references; 00037 #ifndef HAVE_ATOMIC_MACROS 00038 00039 mutable QoreThreadLock mRO; 00040 #endif 00041 00042 public: 00044 DLLEXPORT QoreReferenceCounter(); 00045 00047 DLLEXPORT ~QoreReferenceCounter(); 00048 00050 00053 DLLLOCAL int reference_count() const { 00054 return references; 00055 } 00056 00058 00061 DLLLOCAL bool is_unique() const { 00062 return references == 1; 00063 } 00064 00066 DLLEXPORT void ROreference() const; 00067 00069 00073 DLLEXPORT bool ROdereference() const; 00074 }; 00075 00076 #endif // _QORE_QOREREFERENCECOUNTER_H