All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
AutoVLock.h
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
AutoVLock.h
Qore Programming Language
Copyright 2003 - 2013 David Nichols
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_AUTOVLOCK_H
#define _QORE_AUTOVLOCK_H
class AbstractSmartLock;
struct QLckPtr {
private:
QoreRWLock* rwl;
protected:
DLLLOCAL void unlockIntern() {
assert(rwl);
rwl->unlock();
}
public:
DLLLOCAL QLckPtr() : rwl(0) {
}
DLLLOCAL void set(QoreRWLock* n_rwl) {
rwl = n_rwl;
}
DLLLOCAL QoreRWLock* getRWL() const {
return rwl;
}
DLLLOCAL bool isSet() const {
return rwl;
}
DLLLOCAL void unlockAndClear() {
if (rwl) {
unlockIntern();
rwl = 0;
}
}
DLLLOCAL void clear() {
assert(rwl);
rwl = 0;
}
};
class AutoVLock {
private:
// pointer to lock currently held
QLckPtr lock;
// pointer to object to dereference
QoreObject* o;
public:
// pointer to ExceptionSink object for use with object notifications
ExceptionSink* xsink;
private:
struct qore_avl_private* priv;
DLLLOCAL AutoVLock(const AutoVLock&);
DLLLOCAL AutoVLock& operator=(const AutoVLock&);
DLLLOCAL void* operator new(size_t);
public:
DLLEXPORT AutoVLock(ExceptionSink* n_xsink);
DLLEXPORT ~AutoVLock();
DLLEXPORT operator bool() const;
DLLEXPORT void del();
DLLLOCAL void set(QoreRWLock* n_rwl);
DLLLOCAL void set(QoreObject* n_o, QoreRWLock* n_rwl);
DLLLOCAL QoreRWLock* getRWL() const;
DLLLOCAL QoreObject* getObject() const;
DLLLOCAL void clear();
DLLLOCAL void addMemberNotification(QoreObject* o, const char* member);
};
#endif
AutoVLock
AutoVLock is a container for safely managing global variable and object lock handovers, required for functions accessing global variables and object data where locking is necessary.
Definition: AutoVLock.h:72
AutoVLock::set
DLLLOCAL void set(QoreRWLock *n_rwl)
sets the current lock
AutoVLock::~AutoVLock
DLLEXPORT ~AutoVLock()
releases all locks held and destroys the container
AutoVLock::del
DLLEXPORT void del()
manually releases the lock currently held
AutoVLock::clear
DLLLOCAL void clear()
leaves the lock locked and the object referenced and clears the object and lock pointers ...
AutoVLock::addMemberNotification
DLLLOCAL void addMemberNotification(QoreObject *o, const char *member)
adds an object member notification entry, internal-only
AutoVLock::getObject
DLLLOCAL QoreObject * getObject() const
gets the current object
QoreObject
the implementation of Qore&#39;s object data type, reference counted, dynamically-allocated only ...
Definition: QoreObject.h:56
ExceptionSink
container for holding Qore-language exception information and also for registering a &quot;thread_exit&quot; ca...
Definition: ExceptionSink.h:35
QoreRWLock
provides a simple POSIX-threads-based read-write lock
Definition: QoreRWLock.h:35
AutoVLock::getRWL
DLLLOCAL QoreRWLock * getRWL() const
gets the current read-write lock