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