34#ifndef _QORE_QORERWLOCK_H
35#define _QORE_QORERWLOCK_H
54 pthread_rwlock_init(&
m, 0);
63 pthread_rwlock_destroy(&
m);
70 int rc = pthread_rwlock_wrlock(&
m);
76 return pthread_rwlock_wrlock(&
m);
83 int rc = pthread_rwlock_trywrlock(&
m);
89 return pthread_rwlock_trywrlock(&
m);
100 return pthread_rwlock_unlock(&
m);
105 return pthread_rwlock_rdlock(&
m);
110 return pthread_rwlock_tryrdlock(&
m);
137 DLLLOCAL
void *
operator new(size_t);
176 DLLLOCAL
void *
operator new(size_t);
278 DLLLOCAL
void*
operator new(size_t) =
delete;
295 DLLLOCAL
void *
operator new(size_t);
344class QoreOptionalRWWriteLocker {
349 DLLLOCAL QoreOptionalRWWriteLocker(
QoreRWLock* n_l) : l(n_l->trywrlock() ? 0 : n_l) {
352 DLLLOCAL QoreOptionalRWWriteLocker(
QoreRWLock& n_l) : l(n_l.trywrlock() ? 0 : &n_l) {
355 DLLLOCAL ~QoreOptionalRWWriteLocker() {
360 DLLLOCAL
operator bool()
const {
365class QoreOptionalRWReadLocker {
370 DLLLOCAL QoreOptionalRWReadLocker(
QoreRWLock* n_l) : l(n_l->tryrdlock() ? 0 : n_l) {
373 DLLLOCAL QoreOptionalRWReadLocker(
QoreRWLock& n_l) : l(n_l.tryrdlock() ? 0 : &n_l) {
376 DLLLOCAL ~QoreOptionalRWReadLocker() {
381 DLLLOCAL
operator bool()
const {
386class qore_var_rwlock_priv;
389 friend class qore_var_rwlock_priv;
391 DLLLOCAL QoreVarRWLock();
394 DLLLOCAL ~QoreVarRWLock();
397 DLLLOCAL
void wrlock();
400 DLLLOCAL
int trywrlock();
403 DLLLOCAL
void unlock();
406 DLLLOCAL
void rdlock();
409 DLLLOCAL
int tryrdlock();
412 qore_var_rwlock_priv* priv;
414 DLLLOCAL QoreVarRWLock(qore_var_rwlock_priv* p);
417 QoreVarRWLock(
const QoreVarRWLock&) =
delete;
418 QoreVarRWLock& operator=(
const QoreVarRWLock&) =
delete;
provides a safe and exception-safe way to hold read locks in Qore, only to be used on the stack,...
Definition QoreRWLock.h:128
DLLLOCAL QoreAutoRWReadLocker(QoreRWLock *n_l)
creates the object and grabs the read lock. If parameter is null then no function is performed.
Definition QoreRWLock.h:150
DLLLOCAL ~QoreAutoRWReadLocker()
destroys the object and releases the lock
Definition QoreRWLock.h:156
QoreRWLock * l
the pointer to the lock that will be managed
Definition QoreRWLock.h:141
DLLLOCAL QoreAutoRWReadLocker(QoreRWLock &n_l)
creates the object and grabs the read lock
Definition QoreRWLock.h:145
provides a safe and exception-safe way to hold write locks in Qore, only to be used on the stack,...
Definition QoreRWLock.h:167
DLLLOCAL QoreAutoRWWriteLocker(QoreRWLock &n_l)
creates the object and grabs the write lock
Definition QoreRWLock.h:184
DLLLOCAL ~QoreAutoRWWriteLocker()
destroys the object and releases the lock
Definition QoreRWLock.h:195
QoreRWLock * l
the pointer to the lock that will be managed
Definition QoreRWLock.h:180
DLLLOCAL QoreAutoRWWriteLocker(QoreRWLock *n_l)
creates the object and grabs the write lock. If parameter is null then no function is performed.
Definition QoreRWLock.h:189
provides a simple POSIX-threads-based read-write lock
Definition QoreRWLock.h:47
pthread_rwlock_t m
the actual locking primitive wrapped in this class
Definition QoreRWLock.h:115
DLLLOCAL ~QoreRWLock()
destroys the lock
Definition QoreRWLock.h:59
DLLLOCAL int wrlock()
grabs the write lock
Definition QoreRWLock.h:68
DLLLOCAL QoreRWLock()
creates and initializes the lock
Definition QoreRWLock.h:50
DLLLOCAL int trywrlock()
tries to grab the write lock; does not block if unsuccessful; returns 0 if successful
Definition QoreRWLock.h:81
DLLLOCAL int unlock()
unlocks the lock (assumes the lock is locked)
Definition QoreRWLock.h:94
DLLLOCAL int rdlock()
grabs the read lock
Definition QoreRWLock.h:104
DLLLOCAL int tryrdlock()
tries to grab the read lock; does not block if unsuccessful; returns 0 if successful
Definition QoreRWLock.h:109
provides a safe and exception-safe way to hold read locks in Qore, only to be used on the stack,...
Definition QoreRWLock.h:206
DLLLOCAL void handoffTo(QoreRWLock &n)
Handoff to another read lock.
Definition QoreRWLock.h:255
DLLLOCAL QoreSafeRWReadLocker()
creates an empty object
Definition QoreRWLock.h:209
DLLLOCAL QoreSafeRWReadLocker(QoreRWLock *n_l)
creates the object and grabs the read lock
Definition QoreRWLock.h:219
DLLLOCAL void unlock()
unlocks the object and updates the locked flag, assumes that the lock is held
Definition QoreRWLock.h:240
bool locked
lock flag
Definition QoreRWLock.h:268
DLLLOCAL ~QoreSafeRWReadLocker()
destroys the object and releases the lock
Definition QoreRWLock.h:225
DLLLOCAL void lock()
locks the object and updates the locked flag, assumes that the lock is not already held
Definition QoreRWLock.h:232
DLLLOCAL QoreSafeRWReadLocker(QoreRWLock &n_l)
creates the object and grabs the read lock
Definition QoreRWLock.h:213
QoreRWLock * l
the pointer to the lock that will be managed
Definition QoreRWLock.h:265
DLLLOCAL void stay_locked()
will not unlock the lock when the destructor is run; do not use any other functions of this class aft...
Definition QoreRWLock.h:248
provides a safe and exception-safe way to hold write locks in Qore, only to be used on the stack,...
Definition QoreRWLock.h:286
DLLLOCAL void unlock()
unlocks the object and updates the locked flag, assumes that the lock is held
Definition QoreRWLock.h:331
DLLLOCAL QoreSafeRWWriteLocker(QoreRWLock &n_l)
creates the object and grabs the write lock
Definition QoreRWLock.h:306
QoreRWLock * l
the pointer to the lock that will be managed
Definition QoreRWLock.h:299
DLLLOCAL void lock()
locks the object and updates the locked flag, assumes that the lock is not already held
Definition QoreRWLock.h:324
DLLLOCAL void stay_locked()
will not unlock the lock when the destructor is run; do not use any other functions of this class aft...
Definition QoreRWLock.h:338
DLLLOCAL QoreSafeRWWriteLocker(QoreRWLock *n_l)
creates the object and grabs the write lock
Definition QoreRWLock.h:312
DLLLOCAL ~QoreSafeRWWriteLocker()
destroys the object and releases the lock
Definition QoreRWLock.h:318
bool locked
lock flag
Definition QoreRWLock.h:302
DLLEXPORT int q_gettid() noexcept
returns the current TID number