casa
5.7.0-16
|
Class to hold a (user) lock on a lattice. More...
#include <LatticeLocker.h>
Public Member Functions | |
LatticeLocker (LatticeBase &lattice, FileLocker::LockType, uInt nattempts=0) | |
The constructor acquires a read or write lock on a lattice. More... | |
~LatticeLocker () | |
If the constructor acquired the lock, the destructor releases the lock and flushes the data if changed. More... | |
Bool | hasLock (FileLocker::LockType) const |
Has this process the read or write lock, thus can the table be read or written safely? More... | |
Private Member Functions | |
LatticeLocker (const LatticeLocker &) | |
The copy constructor and assignment are not possible. More... | |
LatticeLocker & | operator= (const LatticeLocker &) |
Private Attributes | |
LatticeBase * | itsLatticePtr |
Bool | itsOwnLock |
Bool | itsHadReadLock |
Class to hold a (user) lock on a lattice.
Public interface
Class LatticeLocker can be used to acquire a (user) lock on a lattice. The lock can be a read or write lock. The destructor releases the lock when needed.
LatticeLocker simply uses the lock
and unlock
function of class Lattice. The advantage of LatticeLocker over these functions is that the destructor of LatticeLocker is called automatically by the system, so unlocking the lattice does not need to be done explicitly and cannot be forgotten. Especially in case of exception handling this can be quite an adavantage.
This class is meant to be used with the UserLocking option. It can, however, also be used with the other locking options. In case of PermanentLocking(Wait) it won't do anything at all. In case of AutoLocking it will acquire and release the lock when needed. However, it is possible that the system releases an auto lock before the LatticeLocker destructor is called.
The constructor of LatticeLocker will look if the lattice is already appropriately locked. If so, it will set a flag to prevent the destructor from unlocking the lattice. In this way nested locks can be used. I.e. one can safely use LatticeLocker in a function without having to be afraid that its destructor would undo a lock set in a higher function.
Similarly LatticeLocker will remember if a lattice was already read-locked, when a write-lock is acquired. In such a case the destructor will try to ensure that the lattice remains read-locked.
LatticeLocker makes it easier to unlock a lattice. It also makes it easier to use locking in a nested way.
Definition at line 112 of file LatticeLocker.h.
|
explicit |
The constructor acquires a read or write lock on a lattice.
If the lattice was already locked, the destructor will not unlock the lattice. This means that the class can be used in a nested way.
The number of attempts (default = forever) can be specified when acquiring the lock does not succeed immediately. When nattempts>1, the system waits 1 second between each attempt, so nattempts is more or less equal to a wait period in seconds. An exception is thrown when the lock cannot be acquired.
casacore::LatticeLocker::~LatticeLocker | ( | ) |
If the constructor acquired the lock, the destructor releases the lock and flushes the data if changed.
|
private |
The copy constructor and assignment are not possible.
Note that only one lock can be held on a lattice, so copying a TableLocker object imposes great difficulties which object should release the lock. It can be solved by turning LatticeLocker into a handle class with a reference counted body class. However, that will only be done when the need arises.
|
inline |
Has this process the read or write lock, thus can the table be read or written safely?
Definition at line 157 of file LatticeLocker.h.
References casacore::LatticeBase::hasLock(), and itsLatticePtr.
|
private |
|
private |
Definition at line 153 of file LatticeLocker.h.
|
private |
Definition at line 151 of file LatticeLocker.h.
Referenced by hasLock().
|
private |
Definition at line 152 of file LatticeLocker.h.