neuray API Programmer's Manual

mi::base::Lock::Block Class Reference

Description

Utility class to acquire a lock that is released by the destructor.

See also:

mi::base::Lock

Public Constructors

 Block( Lock* lock = 0)
Constructor. More...

Public Destructors

 ~Block()
Destructor. More...

Public Member Functions

void release()
Releases the lock. More...
void set( Lock* lock)
Acquires a lock. More...
bool  try_set( Lock* lock)
Tries to acquire a lock. More...

Constructors

mi::​base::​Lock::​Block::Block( Lock* lock = 0) [explicit]

Constructor.

Parameters

lock
If not NULL, this lock is acquired. If NULL, set() can be used to explicitly acquire a lock later.

Destructors

mi::​base::​Lock::​Block::~Block()

Destructor. Releases the lock (if it is acquired).

Member Functions

void mi::​base::​Lock::​Block::release()

Releases the lock. Useful to release the lock before the destructor is called.

void mi::​base::​Lock::​Block::set( Lock* lock)

Acquires a lock. Releases the current lock (if it is set) and acquires the given lock. Useful to acquire a different lock, or to acquire a lock if no lock was acquired in the constructor.

This method does nothing if the passed lock is already acquired by this class.

Parameters

lock
The new lock to acquire.
bool mi::​base::​Lock::​Block::try_set( Lock* lock)

Tries to acquire a lock. Releases the current lock (if it is set) and tries to acquire the given lock. Useful to acquire a different lock without blocking, or to acquire a lock without blocking if no lock was acquired in the constructor.

This method does nothing if the passed lock is already acquired by this class.

Parameters

lock
The new lock to acquire.

Returns

true if the lock was acquired, false otherwise.