32 #ifndef _QORE_ABSTRACTSMARTLOCK_H
34 #define _QORE_ABSTRACTSMARTLOCK_H
37 #include <qore/QoreThreadLock.h>
38 #include <qore/QoreCondition.h>
39 #include <qore/AbstractThreadResource.h>
50 DLLLOCAL AbstractSmartLock() : vl(NULL), tid(-1), waiting(0) {}
51 DLLLOCAL
virtual ~AbstractSmartLock() {}
56 DLLLOCAL
int tryGrab();
57 DLLLOCAL
int release();
60 DLLLOCAL
int self_wait(
int64 timeout_ms) {
61 return timeout_ms ? asl_cond.
wait(&asl_lock, timeout_ms) : asl_cond.
wait(&asl_lock);
65 return timeout_ms ? cond->
wait(&asl_lock, timeout_ms) : cond->
wait(&asl_lock);
70 DLLLOCAL
int get_tid()
const {
return tid; }
71 DLLLOCAL
int get_waiting()
const {
return waiting; }
72 DLLLOCAL
virtual const char *getName()
const = 0;
75 cond_map_t::const_iterator i = cmap.find(cond);
76 return i != cmap.end() ? i->second : 0;
80 enum lock_status_e { Lock_Deleted = -2, Lock_Unlocked = -1 };
86 virtual int releaseImpl() = 0;
88 virtual int grabImpl(
int mtid, VLock *nvl,
ExceptionSink *xsink,
int64 timeout_ms = 0) = 0;
89 virtual int tryGrabImpl(
int mtid, VLock *nvl) = 0;
93 DLLLOCAL
virtual void signalAllImpl();
94 DLLLOCAL
virtual void signalImpl();
96 DLLLOCAL
virtual int cleanupImpl();
98 DLLLOCAL
void mark_and_push(
int mtid, VLock *nvl);
99 DLLLOCAL
void release_and_signal();
100 DLLLOCAL
void grab_intern(
int mtid, VLock *nvl);
101 DLLLOCAL
void release_intern();
102 DLLLOCAL
int verify_wait_unlocked(
int mtid,
ExceptionSink *xsink);
base class for saving data using Qore's thread resource management system
Definition: AbstractThreadResource.h:51
virtual void cleanup(ExceptionSink *xsink)=0
this function is called when a thread terminates and a thread resource is still allocated to the thre...
provides a safe and exception-safe way to hold locks in Qore, only to be used on the stack,...
Definition: QoreThreadLock.h:136
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
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
provides a mutually-exclusive thread lock
Definition: QoreThreadLock.h:49
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:260