34#ifndef _QORE_CLASS_RWLOCK
36#define _QORE_CLASS_RWLOCK
38#include "qore/AbstractSmartLock.h"
43typedef std::map<int, int> tid_map_t;
52typedef std::map<int, VLock*> vlock_map_t;
54class RWLock :
public AbstractSmartLock {
56 DLLEXPORT RWLock(
bool p =
false);
58 DLLEXPORT
virtual ~RWLock();
60 DLLEXPORT
int readLock(ExceptionSink *xsink,
int64 timeout_ms = 0);
61 DLLEXPORT
int readUnlock(ExceptionSink *xsink);
62 DLLEXPORT
int tryReadLock();
64 DLLEXPORT
int numReaders();
66 DLLLOCAL
int getReadWaiting()
const {
69 DLLLOCAL
int getWriteWaiting()
const {
73 DLLLOCAL
bool lockOwner()
const {
77 return readLockOwner();
80 DLLLOCAL
bool writeLockOwner()
const {
84 DLLLOCAL
bool readLockOwner()
const {
86 if (tid > -1 || tid == Lock_Deleted || !num_readers)
91 AutoLocker al(&asl_lock);
92 return tmap.find(mtid) == tmap.end() ? false :
true;
95 DLLLOCAL
virtual const char* getName()
const {
108 DLLLOCAL
int cleanup_read_lock_intern(tid_map_t::iterator i);
109 DLLLOCAL
void mark_read_lock_intern(
int mtid, VLock *nvl);
110 DLLLOCAL
void release_read_lock_intern(tid_map_t::iterator i);
111 DLLLOCAL
int grab_read_lock_intern(
int mtid, VLock *nvl,
int64 timeout_ms, ExceptionSink *xsink);
112 DLLLOCAL
void set_initial_read_lock_intern(
int mtid, VLock *nvl);
114 DLLLOCAL
virtual int cleanupImpl();
115 DLLLOCAL
virtual void signalAllImpl();
116 DLLLOCAL
virtual void signalImpl();
117 DLLLOCAL
virtual int releaseImpl();
118 DLLLOCAL
virtual int releaseImpl(ExceptionSink *xsink);
119 DLLLOCAL
virtual int grabImpl(
int mtid, VLock *nvl, ExceptionSink *xsink,
int64 timeout_ms = 0);
120 DLLLOCAL
virtual int tryGrabImpl(
int mtid, VLock *nvl);
121 DLLLOCAL
virtual int externWaitImpl(
int mtid, QoreCondition *cond, ExceptionSink *xsink,
int64 timeout_ms = 0);
122 DLLLOCAL
virtual void destructorImpl(ExceptionSink *xsink);
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition common.h:266
DLLEXPORT int q_gettid() noexcept
returns the current TID number