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
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/tables/Tables/Table.h>
33#include <casacore/tables/Tables/TableLock.h>
34
35
36namespace casacore { //# NAMESPACE CASACORE - BEGIN
37
38// <summary>
39// Class to hold a (user) lock on a table.
40// </summary>
41
42// <use visibility=export>
43
44// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tTableLockSync.cc">
45// </reviewed>
46
47// <prerequisite>
48//# Classes you should understand before using this one.
49// <li> <linkto class=Table>Table</linkto>
50// <li> <linkto class=TableLock>TableLock</linkto>
51// </prerequisite>
52
53// <synopsis>
54// Class TableLocker can be used to acquire a (user) lock on a table.
55// The lock can be a read or write lock.
56// The destructor only releases the lock if the lock was acquired by the
57// constructor.
58// <p>
59// TableLocker simply uses the <src>lock</src> and <src>unlock</src>
60// function of class Table.
61// The advantage of TableLocker over these functions is that the
62// destructor of TableLocker is called automatically by the system,
63// so unlocking the table does not need to be done explicitly and
64// cannot be forgotten. Especially in case of exception handling this
65// can be quite an adavantage.
66// <p>
67// This class is meant to be used with the UserLocking option.
68// It can, however, also be used with the other locking options.
69// In case of PermanentLocking(Wait) it won't do anything at all.
70// In case of AutoLocking it will acquire and release the lock when
71// needed. However, it is possible that the system releases an
72// auto lock before the TableLocker destructor is called.
73// </synopsis>
74
75// <example>
76// <srcblock>
77// // Open a table to be updated.
78// Table myTable ("theTable", TableLock::UserLocking, Table::Update);
79// // Start of some critical section requiring a lock.
80// {
81// TableLocker lock1 (myTable);
82// ... write the data
83// }
84// // The TableLocker destructor invoked by } unlocked the table.
85// </srcblock>
86// </example>
87
88// <motivation>
89// TableLocker makes it easier to unlock a table.
90// </motivation>
91
92//# <todo asof="$DATE:$">
93//# A List of bugs, limitations, extensions or planned refinements.
94//# </todo>
95
96
98{
99public:
100 // The constructor acquires a read or write lock on a table
101 // which is released by the destructor.
102 // If the table was already locked, the destructor will
103 // not unlock the table.
104 // <br>
105 // The number of attempts (default = forever) can be specified when
106 // acquiring the lock does not succeed immediately. When nattempts>1,
107 // the system waits 1 second between each attempt, so nattempts
108 // is more or less equal to a wait period in seconds.
109 // An exception is thrown when the lock cannot be acquired.
110 explicit TableLocker (Table& table,
112 uInt nattempts = 0);
113
114 // If locked, the destructor releases the lock and flushes the data.
116
117 // The copy constructor and assignment are not possible.
118 // Note that only one lock can be held on a table, so copying a
119 // TableLocker object imposes great difficulties which objects should
120 // release the lock.
121 // It can be solved by turning TableLocker into a handle class
122 // with a reference counted body class.
123 // However, that will only be done when the need arises.
124 // <group>
125 TableLocker (const TableLocker&) = delete;
127 // </group>
128
129 // Has this process the read or write lock, thus can the table
130 // be read or written safely?
132
133private:
134 //# Variables.
137};
138
139
141{
142 return itsTable.hasLock (type);
143}
144
145
146
147} //# NAMESPACE CASACORE - END
148
149#endif
LockType
Define the possible lock types.
Definition FileLocker.h:93
@ Write
Acquire a write lock.
Definition FileLocker.h:97
~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?
Bool hasLock(FileLocker::LockType=FileLocker::Write) const
Has this process the read or write lock, thus can the table be read or written safely?
Definition Table.h:1126
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40