Qore Programming Language Reference Manual  0.9.4.6
Qore::Thread::AbstractSmartLock Class Reference

The abstract base class for locks that support the internal API for use with the Condition class. More...

Inheritance diagram for Qore::Thread::AbstractSmartLock:

Public Member Methods

 constructor ()
 Throws an exception if called directly; this class can only be instantiated by builtin subclasses. More...
 
string getName ()
 Returns the name of the threading class directly inheriting this class. More...
 
bool lockOwner ()
 Returns True if the calling thread owns the lock, False if not. More...
 
int lockTID ()
 Returns the TID of the thread owning the lock or -1 if the lock is currently not acquired. More...
 

Detailed Description

The abstract base class for locks that support the internal API for use with the Condition class.

Restrictions:
Qore::PO_NO_THREAD_CLASSES

This is an abstract class to be inherited by builtin classes that implement the internal Qore API that allows them to be used by the Condition class. Currently the RWLock and Mutex classes inherit this class.

This class cannot be instantiated directly and also cannot be directly inherited by user-defined classes.

Note
This class is not available with the PO_NO_THREAD_CLASSES parse option.

Member Function Documentation

◆ constructor()

Qore::Thread::AbstractSmartLock::constructor ( )

Throws an exception if called directly; this class can only be instantiated by builtin subclasses.

Exceptions
ABSTRACTSMARTLOCK-CONSTRUCTOR-ERRORthis exception is thrown if this class is constructed directly (also if directly inherited by user classes)

◆ getName()

string Qore::Thread::AbstractSmartLock::getName ( )

Returns the name of the threading class directly inheriting this class.

Code Flags:
CONSTANT
Example:
string name = lock.getName();
Returns
the name of the threading class directly inheriting this class

◆ lockOwner()

bool Qore::Thread::AbstractSmartLock::lockOwner ( )

Returns True if the calling thread owns the lock, False if not.

Code Flags:
CONSTANT
Example:
# only grab and release lock if we don't already own it
bool lck = !lock.lockOwner();
if (lck)
lock.lock();
on_exit
if (lck)
lock.unlock();
Returns
True if the calling thread owns the lock, False if not

◆ lockTID()

int Qore::Thread::AbstractSmartLock::lockTID ( )

Returns the TID of the thread owning the lock or -1 if the lock is currently not acquired.

This method normally not useful in practice for anything except checking that the current thread owns the lock, in which case AbstractSmartLock::lockOwner() is better, because if the lock is not owned by the current thread the lock ownership can change at any time.

Code Flags:
CONSTANT
Example:
int tid = lock.lockTID();
Returns
the TID of the thread owning the lock or -1 if the lock is currently not acquired