NVIDIA Iray: Math API Home  Up
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
mi::base::Lock::Block Class Reference

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

Public Member Functions

  Block (Lock *lock=0)
  Constructor. More...
 
  ~Block ()
  Destructor. More...
 
void  set (Lock *lock)
  Acquires a lock. More...
 
bool  try_set (Lock *lock)
  Tries to acquire a lock. More...
 
void  release ()
  Releases the lock. More...
 

Detailed Description

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

See Also
mi::base::Lock

Constructor & Destructor Documentation

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.
mi::base::Lock::Block::~Block ( )

Destructor.

Releases the lock (if it is acquired).

Member Function Documentation

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.