All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
QoreReferenceCounter.h
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
QoreReferenceCounter.h
Qore Programming Language
Copyright (C) 2003 - 2013 David Nichols, all rights reserved
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _QORE_QOREREFERENCECOUNTER_H
#define _QORE_QOREREFERENCECOUNTER_H
#include <qore/common.h>
#include <qore/macros.h>
class QoreThreadLock;
class QoreReferenceCounter {
protected:
mutable int references;
#ifndef HAVE_ATOMIC_MACROS
mutable QoreThreadLock mRO;
#endif
public:
DLLEXPORT QoreReferenceCounter();
DLLEXPORT ~QoreReferenceCounter();
DLLLOCAL int reference_count() const {
return references;
}
DLLLOCAL bool is_unique() const {
return references == 1;
}
DLLEXPORT void ROreference() const;
DLLEXPORT bool ROdereference() const;
};
#endif // _QORE_QOREREFERENCECOUNTER_H