casacore
Loading...
Searching...
No Matches
TableLock.h
Go to the documentation of this file.
1// # TableLock.h: Class to hold table lock options
2// # Copyright (C) 1997,1998,2000,2001
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_TABLELOCK_H
27#define TABLES_TABLELOCK_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/IO/LockFile.h>
32
33namespace casacore { // # NAMESPACE CASACORE - BEGIN
34
35// <summary>
36// Class to hold table lock options.
37// </summary>
38
39// <use visibility=local>
40
41// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tTable" demos="">
42// </reviewed>
43
44// <prerequisite>
45// <li> class <linkto class=Table>Table</linkto>
46// <li> class <linkto class=LockFile>LockFile</linkto>
47// </prerequisite>
48
49// <synopsis>
50// This class keeps the Table lock options.
51// Currently these are the LockingOption and the inspection interval.
52// <p>
53// It also keeps the <src>LockFile</src> object used to do the
54// actual locking/unlocking.
55//
56// It is possible to disable locking by building casacore with -DAIPS_TABLE_NOLOCKING
57// or by setting the aipsrc variable table.nolocking=true.
58
59// <motivation>
60// Encapsulate Table locking info.
61// </motivation>
62
63class TableLock {
64 public:
65 // Define the possible table locking options.
66 // They offer the user the possibility to lock and synchronize access
67 // to the table. A lot of locking degrades table performance; not only
68 // because acquiring/releasing locks takes time, but especially
69 // because table data has to be synchronized (thus written to disk)
70 // when a lock is released. Otherwise the other processes see data
71 // which is not up-to-date.
72 //
73 // Building Casacore with -DTABLE_NOLOCKING or setting aipsrc variable
74 // table.nolocking=1 forces lock option NoLocking.
76 // The table is permanently locked.
77 // A lock is set at the beginning and only released when
78 // the table is closed. A read lock is used when the table is
79 // opened for readonly; otherwise a write lock is used.
80 // This means that multiple readers are possible.
81 // The Table constructor exits with an exception when the
82 // lock cannot be acquired.
84 // The same as above, but the table constructor waits
85 // until the lock gets available.
87 // The system takes care of acquiring/releasing locks.
88 // In principle it keeps the table locked, but from time to
89 // time (defined by the inspection interval) it is checked whether
90 // another process wants to access the table. If so, the lock
91 // is released and probably re-acquired later.
92 // This mode is the default mode.
94 // The user is taking care of locking the table by means
95 // of the Table functions <src>lock</src> and <src>unlock</src>.
96 // In this way transaction processing can be implemented.
98 // The system takes care of acquiring/releasing locks.
99 // It is similar to AutoLocking, but no locks are needed for
100 // reading.
102 // The user is taking care of locking the table by means
103 // of the Table functions <src>lock</src> and <src>unlock</src>.
104 // It is similar to UserLocking, but no locks are needed for
105 // reading.
107 // Do not do any locking at all. This should be used with care
108 // because concurrent access might result in table corruption.
110 // This is the default locking option.
111 // It means that AutoLocking will be used if the table is not
112 // opened yet. Otherwise the locking options of the PlainTable
113 // object already in use will be used.
115 };
116
117 // Construct with given option and interval.
118 // The default <src>LockOption</src> is <src>AutoLocking</src>.
119 // In case of AutloLocking the inspection interval defines how often
120 // the table system checks if another process needs a lock on the table.
121 // It defaults to 5 seconds.
122 // The maxWait defines the maximum number of seconds the table system
123 // waits when acquiring a lock in AutoLocking mode. The default
124 // is 0 seconds meaning indefinitely.
125 // <group>
127 TableLock(LockOption option, double inspectionInterval, uInt maxWait = 0);
128 // </group>
129
130 // Copy constructor.
131 TableLock(const TableLock& that);
132
133 // Assignment.
135
136 // Merge that TableLock with this TableLock object by taking the
137 // maximum option and minimum inspection interval.
138 // The option order (ascending) is UserLocking, AutoLocking,
139 // PermanentLocking.
140 // When an interval was defaulted, it is not taken into account.
141 // An option DefaultLocking is not taken into account.
142 void merge(const TableLock& that);
143
144 // Get the locking option.
145 LockOption option() const;
146
147 // Is read locking needed?
148 Bool readLocking() const;
149
150 // Is permanent locking used?
151 Bool isPermanent() const;
152
153 // Get the inspection interval.
154 double interval() const;
155
156 // Get the maximum wait period in AutoLocking mode.
157 uInt maxWait() const;
158
159 // Is table locking disabled (because AIPS_TABLE_NOLOCKING or table.nolocking is set)?
161
162 private:
169
170 // Set itsOption and itsReadLocking when needed.
171 void init();
172};
173
175
177
181
182inline double TableLock::interval() const { return itsInterval; }
183
184inline uInt TableLock::maxWait() const { return itsMaxWait; }
185
186} // namespace casacore
187
188#endif
TableLock(LockOption option, double inspectionInterval, uInt maxWait=0)
LockOption
Define the possible table locking options.
Definition TableLock.h:75
@ UserLocking
The user is taking care of locking the table by means of the Table functions lock and unlock.
Definition TableLock.h:97
@ AutoLocking
The system takes care of acquiring/releasing locks.
Definition TableLock.h:93
@ AutoNoReadLocking
The system takes care of acquiring/releasing locks.
Definition TableLock.h:101
@ DefaultLocking
This is the default locking option.
Definition TableLock.h:114
@ UserNoReadLocking
The user is taking care of locking the table by means of the Table functions lock and unlock.
Definition TableLock.h:106
@ PermanentLocking
The table is permanently locked.
Definition TableLock.h:83
@ NoLocking
Do not do any locking at all.
Definition TableLock.h:109
@ PermanentLockingWait
The same as above, but the table constructor waits until the lock gets available.
Definition TableLock.h:86
Bool isPermanent() const
Is permanent locking used?
Definition TableLock.h:178
void init()
Set itsOption and itsReadLocking when needed.
TableLock(LockOption option=DefaultLocking)
Construct with given option and interval.
Bool readLocking() const
Is read locking needed?
Definition TableLock.h:176
LockOption itsOption
Definition TableLock.h:163
TableLock & operator=(const TableLock &that)
Assignment.
static Bool lockingDisabled()
Is table locking disabled (because AIPS_TABLE_NOLOCKING or table.nolocking is set)?
double interval() const
Get the inspection interval.
Definition TableLock.h:182
uInt maxWait() const
Get the maximum wait period in AutoLocking mode.
Definition TableLock.h:184
TableLock(const TableLock &that)
Copy constructor.
void merge(const TableLock &that)
Merge that TableLock with this TableLock object by taking the maximum option and minimum inspection i...
LockOption option() const
Get the locking option.
Definition TableLock.h:174
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