4.18. Thread::AbstractSmartLock Class

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

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.

Table 4.715. AbstractSmartLock Method Overview

Method

Except?

Description

AbstractSmartLock::constructor()

Y

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

::AbstractSmartLock::destructor()

N

Performs no action.

AbstractSmartLock::copy()

N

Performs no action.

string AbstractSmartLock::getName()

N

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

bool AbstractSmartLock::lockOwner()

N

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

int AbstractSmartLock::lockTID()

N

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


4.18.1. AbstractSmartLock::constructor()

Synopsis

Throws an exception if called directly or if inherited by a user-defined class; this class can only be instantiated by builtin subclasses.

Table 4.716. Exceptions Thrown by AbstractSmartLock::constructor()

err

desc

ABSTRACTSMARTLOCK-CONSTRUCTOR-ERROR

This class cannot be instantiated directly or inherited by user code.


4.18.2. AbstractSmartLock::destructor()

Synopsis

Performs no action.

4.18.3. AbstractSmartLock::copy()

Synopsis

Performs no action.

4.18.4. AbstractSmartLock::getName()

Synopsis

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

Prototype

string AbstractSmartLock::getName()

Example
my $name = $lock.getName();

Table 4.717. Return Values for AbstractSmartLock::getName()

Return Type

Description

string

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


4.18.5. AbstractSmartLock::lockOwner()

Synopsis

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

Prototype

bool AbstractSmartLock::lockOwner()

Example
# only grab and release lock if we don't already own it
if (!$lock.lockOwner())
    $lock.lock();
on_exit
    if (!$lock.lockOwner())
	$lock.unlock();

Table 4.718. Return Values for AbstractSmartLock::lockOwner()

Return Type

Description

bool

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


4.18.6. AbstractSmartLock::lockTID()

Synopsis

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.

Prototype

int AbstractSmartLock::lockTID()

Example
my int $tid = $lock.lockTID();

Table 4.719. Return Values for AbstractSmartLock::lockTID()

Return Type

Description

int

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