casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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: aips2-request@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 //# $Id$
27 
28 #ifndef TABLES_TABLELOCK_H
29 #define TABLES_TABLELOCK_H
30 
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
35 
36 
37 namespace casacore { //# NAMESPACE CASACORE - BEGIN
38 
39 // <summary>
40 // Class to hold table lock options.
41 // </summary>
42 
43 // <use visibility=local>
44 
45 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tTable" demos="">
46 // </reviewed>
47 
48 // <prerequisite>
49 // <li> class <linkto class=Table>Table</linkto>
50 // <li> class <linkto class=LockFile>LockFile</linkto>
51 // </prerequisite>
52 
53 // <synopsis>
54 // This class keeps the Table lock options.
55 // Currently these are the LockingOption and the inspection interval.
56 // <p>
57 // It also keeps the <src>LockFile</src> object used to do the
58 // actual locking/unlocking.
59 
60 // <motivation>
61 // Encapsulate Table locking info.
62 // </motivation>
63 
64 
65 class TableLock
66 {
67 public:
68  // Define the possible table locking options.
69  // They offer the user the possibility to lock and synchronize access
70  // to the table. A lot of locking degrades table performance; not only
71  // because acquiring/releasing locks takes time, but especially
72  // because table data has to be synchronized (thus written to disk)
73  // when a lock is released. Otherwise the other processes see data
74  // which is not up-to-date.
75  enum LockOption {
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.
134  TableLock& operator= (const TableLock& that);
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 was set)?
160  static Bool lockingDisabled();
161 
162 
163 private:
167  double itsInterval;
170 
171 
172  // Set itsOption and itsReadLocking when needed.
173  void init();
174 };
175 
176 
177 
179 {
180  return itsOption;
181 }
182 
184 {
185  return itsReadLocking;
186 }
187 
189 {
190  return (itsOption == PermanentLocking
192 }
193 
194 inline double TableLock::interval() const
195 {
196  return itsInterval;
197 }
198 
199 inline uInt TableLock::maxWait() const
200 {
201  return itsMaxWait;
202 }
203 
204 
205 
206 } //# NAMESPACE CASACORE - END
207 
208 #endif
static Bool lockingDisabled()
Is table locking disabled (because AIPS_TABLE_NOLOCKING was set)?
The same as above, but the table constructor waits until the lock gets available. ...
Definition: TableLock.h:86
LockOption
Define the possible table locking options.
Definition: TableLock.h:75
The table is permanently locked.
Definition: TableLock.h:83
Bool readLocking() const
Is read locking needed?
Definition: TableLock.h:183
LockOption option() const
Get the locking option.
Definition: TableLock.h:178
TableLock & operator=(const TableLock &that)
Assignment.
double interval() const
Get the inspection interval.
Definition: TableLock.h:194
The user is taking care of locking the table by means of the Table functions lock and unlock...
Definition: TableLock.h:97
The system takes care of acquiring/releasing locks.
Definition: TableLock.h:93
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
void init()
Set itsOption and itsReadLocking when needed.
Class to hold table lock options.
Definition: TableLock.h:65
This is the default locking option.
Definition: TableLock.h:114
uInt maxWait() const
Get the maximum wait period in AutoLocking mode.
Definition: TableLock.h:199
void merge(const TableLock &that)
Merge that TableLock with this TableLock object by taking the maximum option and minimum inspection i...
The system takes care of acquiring/releasing locks.
Definition: TableLock.h:101
LockOption itsOption
Definition: TableLock.h:164
Do not do any locking at all.
Definition: TableLock.h:109
The user is taking care of locking the table by means of the Table functions lock and unlock...
Definition: TableLock.h:106
Bool isPermanent() const
Is permanent locking used?
Definition: TableLock.h:188
TableLock(LockOption option=DefaultLocking)
Construct with given option and interval.
unsigned int uInt
Definition: aipstype.h:51
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42