Qore Programming Language: include/qore/AutoVLock.h (6585) Source File

Qore Programming Language 0.8.11

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

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
AutoVLock.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3 AutoVLock.h
4
5 Qore Programming Language
6
7 Copyright 2003 - 2013 David Nichols
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_AUTOVLOCK_H
25
26 #define _QORE_AUTOVLOCK_H
27
28 class AbstractSmartLock;
29
30 struct QLckPtr {
31 private:
32 QoreRWLock* rwl;
33
34 protected:
35 DLLLOCAL void unlockIntern() {
36 assert(rwl);
37 rwl->unlock();
38 }
39
40 public:
41 DLLLOCAL QLckPtr() : rwl(0) {
42 }
43
44 DLLLOCAL void set(QoreRWLock* n_rwl) {
45 rwl = n_rwl;
46 }
47
48 DLLLOCAL QoreRWLock* getRWL() const {
49 return rwl;
50 }
51
52 DLLLOCAL bool isSet() const {
53 return rwl;
54 }
55
56 DLLLOCAL void unlockAndClear() {
57 if (rwl) {
58 unlockIntern();
59 rwl = 0;
60 }
61 }
62
63 DLLLOCAL void clear() {
64 assert(rwl);
65 rwl = 0;
66 }
67 };
68
70
72 class AutoVLock {
73 private:
74 // pointer to lock currently held
75 QLckPtr lock;
76
77 // pointer to object to dereference
78 QoreObject* o;
79
80 public:
81 // pointer to ExceptionSink object for use with object notifications
82 ExceptionSink* xsink;
83
84 private:
86 struct qore_avl_private* priv;
87
89 DLLLOCAL AutoVLock(const AutoVLock&);
91 DLLLOCAL AutoVLock& operator=(const AutoVLock&);
93 DLLLOCAL void* operator new(size_t);
94
95 public:
97
99 DLLEXPORT AutoVLock(ExceptionSink* n_xsink);
100
102 DLLEXPORT ~AutoVLock();
103
105 DLLEXPORT operator bool() const;
106
108 DLLEXPORT void del();
109
111 DLLLOCAL void set(QoreRWLock* n_rwl);
112
114 DLLLOCAL void set(QoreObject* n_o, QoreRWLock* n_rwl);
115
117 DLLLOCAL QoreRWLock* getRWL() const;
118
120 DLLLOCAL QoreObject* getObject() const;
121
123 DLLLOCAL void clear();
124
126
129 DLLLOCAL void addMemberNotification(QoreObject* o, const char* member);
130 };
131
132 #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'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 "thread_exit" 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