34 #ifndef _QORE_VAR_RWLOCK_PRIV_H
35 #define _QORE_VAR_RWLOCK_PRIV_H
37 class qore_var_rwlock_priv {
39 DLLLOCAL
virtual void notifyIntern() {
43 DLLLOCAL qore_var_rwlock_priv(
const qore_var_rwlock_priv&);
45 DLLLOCAL qore_var_rwlock_priv& operator=(
const qore_var_rwlock_priv&);
58 DLLLOCAL qore_var_rwlock_priv() : write_tid(-1), readers(0), read_waiting(0), write_waiting(0), has_notify(false) {
62 DLLLOCAL
virtual ~qore_var_rwlock_priv() {
66 DLLLOCAL
void wrlock() {
69 assert(tid != write_tid);
71 while (readers || write_tid != -1) {
81 DLLLOCAL
int trywrlock() {
84 assert(tid != write_tid);
85 if (readers || write_tid != -1)
93 DLLLOCAL
void unlock() {
96 if (write_tid == tid) {
106 unlock_read_signal();
111 DLLLOCAL
void rdlock() {
114 while (write_tid != -1) {
124 DLLLOCAL
int tryrdlock() {
134 DLLLOCAL
void unlock_signal() {
137 else if (read_waiting)
141 DLLLOCAL
void unlock_read_signal() {
148 class QoreAutoVarRWReadLocker {
151 DLLLOCAL QoreAutoVarRWReadLocker(
const QoreAutoVarRWReadLocker&);
154 DLLLOCAL QoreAutoVarRWReadLocker& operator=(
const QoreAutoVarRWReadLocker&);
157 DLLLOCAL
void *
operator new(size_t);
165 DLLLOCAL QoreAutoVarRWReadLocker(QoreVarRWLock &n_l) : l(&n_l) {
170 DLLLOCAL QoreAutoVarRWReadLocker(QoreVarRWLock *n_l) : l(n_l) {
175 DLLLOCAL ~QoreAutoVarRWReadLocker() {
180 class QoreAutoVarRWWriteLocker {
183 DLLLOCAL QoreAutoVarRWWriteLocker(
const QoreAutoVarRWWriteLocker&);
186 DLLLOCAL QoreAutoVarRWWriteLocker& operator=(
const QoreAutoVarRWWriteLocker&);
189 DLLLOCAL
void *
operator new(size_t);
197 DLLLOCAL QoreAutoVarRWWriteLocker(QoreVarRWLock &n_l) : l(&n_l) {
202 DLLLOCAL QoreAutoVarRWWriteLocker(QoreVarRWLock *n_l) : l(n_l) {
207 DLLLOCAL ~QoreAutoVarRWWriteLocker() {
212 class QoreSafeVarRWReadLocker {
215 DLLLOCAL QoreSafeVarRWReadLocker(
const QoreSafeVarRWReadLocker&);
218 DLLLOCAL QoreSafeVarRWReadLocker& operator=(
const QoreSafeVarRWReadLocker&);
221 DLLLOCAL
void *
operator new(size_t);
232 DLLLOCAL QoreSafeVarRWReadLocker(QoreVarRWLock &n_l) : l(&n_l) {
238 DLLLOCAL QoreSafeVarRWReadLocker(QoreVarRWLock *n_l) : l(n_l) {
244 DLLLOCAL ~QoreSafeVarRWReadLocker() {
250 DLLLOCAL
void lock() {
257 DLLLOCAL
void unlock() {
264 DLLLOCAL
void stay_locked() {
270 class QoreSafeVarRWWriteLocker {
273 DLLLOCAL QoreSafeVarRWWriteLocker(
const QoreSafeVarRWWriteLocker&);
276 DLLLOCAL QoreSafeVarRWWriteLocker& operator=(
const QoreSafeVarRWWriteLocker&);
279 DLLLOCAL
void *
operator new(size_t);
290 DLLLOCAL QoreSafeVarRWWriteLocker(QoreVarRWLock &n_l) : l(&n_l) {
296 DLLLOCAL QoreSafeVarRWWriteLocker(QoreVarRWLock *n_l) : l(n_l) {
302 DLLLOCAL ~QoreSafeVarRWWriteLocker() {
308 DLLLOCAL
void lock() {
315 DLLLOCAL
void unlock() {
322 DLLLOCAL
void stay_locked() {
328 class QoreOptionalVarRWWriteLocker {
333 DLLLOCAL QoreOptionalVarRWWriteLocker(QoreVarRWLock* n_l) : l(n_l->trywrlock() ? 0 : n_l) {
336 DLLLOCAL QoreOptionalVarRWWriteLocker(QoreVarRWLock& n_l) : l(n_l.trywrlock() ? 0 : &n_l) {
339 DLLLOCAL ~QoreOptionalVarRWWriteLocker() {
344 DLLLOCAL
operator bool()
const {
349 class QoreOptionalVarRWReadLocker {
354 DLLLOCAL QoreOptionalVarRWReadLocker(QoreVarRWLock* n_l) : l(n_l->tryrdlock() ? 0 : n_l) {
357 DLLLOCAL QoreOptionalVarRWReadLocker(QoreVarRWLock& n_l) : l(n_l.tryrdlock() ? 0 : &n_l) {
360 DLLLOCAL ~QoreOptionalVarRWReadLocker() {
365 DLLLOCAL
operator bool()
const {
provides a safe and exception-safe way to hold locks in Qore, only to be used on the stack,...
Definition: QoreThreadLock.h:136
a thread condition class implementing a wrapper for pthread_cond_t
Definition: QoreCondition.h:45
DLLEXPORT int wait(pthread_mutex_t *m)
blocks a thread on a mutex until the condition is signaled
DLLEXPORT int signal()
signals a single waiting thread to wake up
DLLEXPORT int broadcast()
singles all threads blocked on this condition to wake up
provides a mutually-exclusive thread lock
Definition: QoreThreadLock.h:49
DLLEXPORT int q_gettid() noexcept
returns the current TID number