Loading...
Searching...
No Matches
casacore::TableLocker Class Reference
tables package (libcasa_tables) » Tables_module

More...

`#include <TableLocker.h>`

## Public Member Functions

| TableLocker (Table &table, FileLocker::LockType=FileLocker::Write, uInt nattempts=0)
| The constructor acquires a read or write lock on a table which is released by the destructor.
| ~TableLocker ()
| If locked, the destructor releases the lock and flushes the data.
| TableLocker (const TableLocker &)=delete
| The copy constructor and assignment are not possible.
TableLocker & | operator= (const TableLocker &)=delete
Bool | hasLock (FileLocker::LockType=FileLocker::Write) const
| Has this process the read or write lock, thus can the table be read or written safely?

## Private Attributes

Table | itsTable
bool | itsHadLock

## Detailed Description

Class to hold a (user) lock on a table.

### Intended use:

Public interface

### Review Status

Reviewed By:
  UNKNOWN
Date Reviewed:
  before2004/08/25
Test programs:
  tTableLockSync

### Prerequisite

- Table
- TableLock

### Synopsis

Class TableLocker can be used to acquire a (user) lock on a table. The lock can be a read or write lock. The destructor only releases the lock if the lock was acquired by the constructor.

TableLocker simply uses the lock and unlock function of class Table. The advantage of TableLocker over these functions is that the destructor of TableLocker is called automatically by the system, so unlocking the table 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 TableLocker destructor is called.

### Example

// Open a table to be updated.
Table myTable ("theTable", TableLock::UserLocking, Table::Update);
// Start of some critical section requiring a lock.
{
TableLocker lock1 (myTable);
... write the data
}
// The TableLocker destructor invoked by } unlocked the table.
casacore::TableLock::UserLocking
@ UserLocking
The user is taking care of locking the table by means of the Table functions lock and unlock.
Definition TableLock.h:101
casacore::TableLocker::TableLocker
TableLocker(Table &table, FileLocker::LockType=FileLocker::Write, uInt nattempts=0)
The constructor acquires a read or write lock on a table which is released by the destructor.
casacore::Table
Definition Table.h:157
casacore::Table::Update
@ Update
update existing table
Definition Table.h:181
casacore::write
virtual int write(FitsOutput &)

### Motivation

TableLocker makes it easier to unlock a table.

Definition at line 97 of file TableLocker.h.

## Constructor & Destructor Documentation

## TableLocker() [1/2]

casacore::TableLocker::TableLocker | ( | Table & | table,
|  | FileLocker::LockType | = FileLocker::Write,
|  | uInt | nattempts = 0 )

explicit

The constructor acquires a read or write lock on a table which is released by the destructor.

If the table was already locked, the destructor will not unlock the table.
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.

References casacore::FileLocker::Write.

Referenced by operator=(), and TableLocker().

## ~TableLocker()

casacore::TableLocker::~TableLocker | ( |  | ) |

If locked, the destructor releases the lock and flushes the data.

## TableLocker() [2/2]

casacore::TableLocker::TableLocker | ( | const TableLocker & |  | ) |

delete

The copy constructor and assignment are not possible.

Note that only one lock can be held on a table, so copying a TableLocker object imposes great difficulties which objects should release the lock. It can be solved by turning TableLocker into a handle class with a reference counted body class. However, that will only be done when the need arises.

References TableLocker().

## Member Function Documentation

## hasLock()

Bool casacore::TableLocker::hasLock | ( | FileLocker::LockType | type = FileLocker::Write | ) | const

inline

Has this process the read or write lock, thus can the table be read or written safely?

Definition at line 140 of file TableLocker.h.

References itsTable.

## operator=()

TableLocker & casacore::TableLocker::operator= | ( | const TableLocker & |  | ) |

delete

References TableLocker(), and casacore::FileLocker::Write.

## Member Data Documentation

## itsHadLock

bool casacore::TableLocker::itsHadLock

private

Definition at line 136 of file TableLocker.h.

## itsTable

Table casacore::TableLocker::itsTable

private

Definition at line 135 of file TableLocker.h.

Referenced by hasLock().

The documentation for this class was generated from the following file:

- tables/Tables/TableLocker.h