casacore
Loading...
Searching...
No Matches
TableLocker.h
Go to the documentation of this file.
1// # TableLocker.h: Class to hold a (user) lock on a table
2// # Copyright (C) 1998,2000
3// # Associated Universities, Inc. Washington DC, USA.
4// #
5// # This library is free software; you can redistribute it and/or modify it
6// # under the terms of the GNU Library General Public License as published by
7// # the Free Software Foundation; either version 2 of the License, or (at your
8// # option) any later version.
9// #
10// # This library is distributed in the hope that it will be useful, but WITHOUT
11// # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12// # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13// # License for more details.
14// #
15// # You should have received a copy of the GNU Library General Public License
16// # along with this library; if not, write to the Free Software Foundation,
17// # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18// #
19// # Correspondence concerning AIPS++ should be addressed as follows:
20// # Internet email: casa-feedback@nrao.edu.
21// # Postal address: AIPS++ Project Office
22// # National Radio Astronomy Observatory
23// # 520 Edgemont Road
24// # Charlottesville, VA 22903-2475 USA
25
26#ifndef TABLES_TABLELOCKER_H
27#define TABLES_TABLELOCKER_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/tables/Tables/Table.h>
32#include <casacore/tables/Tables/TableLock.h>
33
34namespace casacore { // # NAMESPACE CASACORE - BEGIN
35
36// <summary>
37// Class to hold a (user) lock on a table.
38// </summary>
39
40// <use visibility=export>
41
42// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tTableLockSync.cc">
43// </reviewed>
44
45// <prerequisite>
46// # Classes you should understand before using this one.
47// <li> <linkto class=Table>Table</linkto>
48// <li> <linkto class=TableLock>TableLock</linkto>
49// </prerequisite>
50
51// <synopsis>
52// Class TableLocker can be used to acquire a (user) lock on a table.
53// The lock can be a read or write lock.
54// The destructor only releases the lock if the lock was acquired by the
55// constructor.
56// <p>
57// TableLocker simply uses the <src>lock</src> and <src>unlock</src>
58// function of class Table.
59// The advantage of TableLocker over these functions is that the
60// destructor of TableLocker is called automatically by the system,
61// so unlocking the table does not need to be done explicitly and
62// cannot be forgotten. Especially in case of exception handling this
63// can be quite an adavantage.
64// <p>
65// This class is meant to be used with the UserLocking option.
66// It can, however, also be used with the other locking options.
67// In case of PermanentLocking(Wait) it won't do anything at all.
68// In case of AutoLocking it will acquire and release the lock when
69// needed. However, it is possible that the system releases an
70// auto lock before the TableLocker destructor is called.
71// </synopsis>
72
73// <example>
74// <srcblock>
75// // Open a table to be updated.
76// Table myTable ("theTable", TableLock::UserLocking, Table::Update);
77// // Start of some critical section requiring a lock.
78// {
79// TableLocker lock1 (myTable);
80// ... write the data
81// }
82// // The TableLocker destructor invoked by } unlocked the table.
83// </srcblock>
84// </example>
85
86// <motivation>
87// TableLocker makes it easier to unlock a table.
88// </motivation>
89
90// # <todo asof="$DATE:$">
91// # A List of bugs, limitations, extensions or planned refinements.
92// # </todo>
93
95 public:
96 // The constructor acquires a read or write lock on a table
97 // which is released by the destructor.
98 // If the table was already locked, the destructor will
99 // not unlock the table.
100 // <br>
101 // The number of attempts (default = forever) can be specified when
102 // acquiring the lock does not succeed immediately. When nattempts>1,
103 // the system waits 1 second between each attempt, so nattempts
104 // is more or less equal to a wait period in seconds.
105 // An exception is thrown when the lock cannot be acquired.
106 explicit TableLocker(Table& table, FileLocker::LockType = FileLocker::Write, uInt nattempts = 0);
107
108 // If locked, the destructor releases the lock and flushes the data.
110
111 // The copy constructor and assignment are not possible.
112 // Note that only one lock can be held on a table, so copying a
113 // TableLocker object imposes great difficulties which objects should
114 // release the lock.
115 // It can be solved by turning TableLocker into a handle class
116 // with a reference counted body class.
117 // However, that will only be done when the need arises.
118 // <group>
119 TableLocker(const TableLocker&) = delete;
121 // </group>
122
123 // Has this process the read or write lock, thus can the table
124 // be read or written safely?
126
127 private:
128 // # Variables.
131};
132
134
135} // namespace casacore
136
137#endif
LockType
Define the possible lock types.
Definition FileLocker.h:89
@ Write
Acquire a write lock.
Definition FileLocker.h:93
~TableLocker()
If locked, the destructor releases the lock and flushes the data.
TableLocker & operator=(const TableLocker &)=delete
TableLocker(const TableLocker &)=delete
The copy constructor and assignment are not possible.
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.
Bool hasLock(FileLocker::LockType=FileLocker::Write) const
Has this process the read or write lock, thus can the table be read or written safely?
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40