All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
AutoVLock.h
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
AutoVLock.h
Qore Programming Language
Copyright (C) 2003 - 2017 Qore Technologies, s.r.o.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Note that the Qore library is released under a choice of three open-source
licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
information.
*/
#ifndef _QORE_AUTOVLOCK_H
#define _QORE_AUTOVLOCK_H
class AbstractSmartLock;
struct QLckPtr {
private:
QoreVarRWLock* rwl;
protected:
DLLLOCAL void unlockIntern() {
assert(rwl);
rwl->unlock();
}
public:
DLLLOCAL QLckPtr() : rwl(0) {
}
DLLLOCAL void set(QoreVarRWLock* n_rwl) {
rwl = n_rwl;
}
DLLLOCAL QoreVarRWLock* 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&) = delete;
DLLLOCAL AutoVLock& operator=(const AutoVLock&) = delete;
DLLLOCAL void* operator new(size_t) = delete;
public:
DLLEXPORT AutoVLock(ExceptionSink* n_xsink);
DLLEXPORT AutoVLock(AutoVLock&& o) = default;
DLLEXPORT ~AutoVLock();
DLLEXPORT operator bool() const;
DLLEXPORT void del();
DLLLOCAL void set(QoreVarRWLock* n_rwl);
DLLLOCAL void set(QoreObject* n_o, QoreVarRWLock* n_rwl);
DLLLOCAL QoreVarRWLock* 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:80
AutoVLock::~AutoVLock
DLLEXPORT ~AutoVLock()
releases all locks held and destroys the container
AutoVLock::del
DLLEXPORT void del()
manually releases the lock currently held
AutoVLock::set
DLLLOCAL void set(QoreVarRWLock *n_rwl)
sets the current lock
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:62
ExceptionSink
container for holding Qore-language exception information and also for registering a &quot;thread_exit&quot; ca...
Definition: ExceptionSink.h:47
AutoVLock::getRWL
DLLLOCAL QoreVarRWLock * getRWL() const
gets the current read-write lock