|
Qore Programming Language
0.9.16
|
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>
47 enum lock_status_e { Lock_Deleted = -2, Lock_Unlocked = -1 };
53 virtual int releaseImpl() = 0;
55 virtual int grabImpl(
int mtid, VLock *nvl,
ExceptionSink *xsink,
int64 timeout_ms = 0) = 0;
56 virtual int tryGrabImpl(
int mtid, VLock *nvl) = 0;
60 DLLLOCAL
virtual void signalAllImpl();
61 DLLLOCAL
virtual void signalImpl();
62 DLLLOCAL
virtual void cleanupImpl();
64 DLLLOCAL
void mark_and_push(
int mtid, VLock *nvl);
65 DLLLOCAL
void release_and_signal();
66 DLLLOCAL
void grab_intern(
int mtid, VLock *nvl);
67 DLLLOCAL
void release_intern();
68 DLLLOCAL
int verify_wait_unlocked(
int mtid,
ExceptionSink *xsink);
74 DLLLOCAL AbstractSmartLock() : vl(NULL), tid(-1), waiting(0) {}
75 DLLLOCAL
virtual ~AbstractSmartLock() {}
80 DLLLOCAL
int tryGrab();
81 DLLLOCAL
int release();
84 DLLLOCAL
int self_wait(
int64 timeout_ms) {
85 return timeout_ms ? asl_cond.
wait(&asl_lock, timeout_ms) : asl_cond.
wait(&asl_lock);
89 return timeout_ms ? cond->
wait(&asl_lock, timeout_ms) : cond->
wait(&asl_lock);
94 DLLLOCAL
int get_tid()
const {
return tid; }
95 DLLLOCAL
int get_waiting()
const {
return waiting; }
96 DLLLOCAL
virtual const char *getName()
const = 0;
99 cond_map_t::const_iterator i = cmap.find(cond);
100 return i != cmap.end() ? i->second : 0;
a thread condition class implementing a wrapper for pthread_cond_t
Definition: QoreCondition.h:45
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
provides a safe and exception-safe way to hold locks in Qore, only to be used on the stack,...
Definition: QoreThreadLock.h:136
base class for saving data using Qore's thread resource management system
Definition: AbstractThreadResource.h:51
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
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 mutually-exclusive thread lock
Definition: QoreThreadLock.h:49
DLLEXPORT int wait(pthread_mutex_t *m)
blocks a thread on a mutex until the condition is signaled