casacore
Loading...
Searching...
No Matches
ExternalLockSync.h
Go to the documentation of this file.
1//# ExternalLockSync.h: Class to hold table lock data
2//# Copyright (C) 1997,1998
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_EXTERNALLOCKSYNC_H
27#define TABLES_EXTERNALLOCKSYNC_H
28
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/tables/Tables/TableLockData.h>
33#include <casacore/tables/Tables/TableSyncData.h>
34
35
36namespace casacore { //# NAMESPACE CASACORE - BEGIN
37
38// <summary>
39// Class to hold table lock data.
40// </summary>
41
42// <use visibility=local>
43
44// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tTable" demos="">
45// </reviewed>
46
47// <prerequisite>
48// <li> class <linkto class=Table>TableLock</linkto>
49// </prerequisite>
50
51// <synopsis>
52// This class keeps the <src>LockFile</src> object used to do the
53// actual locking/unlocking.
54// It also keeps the synchronization information.
55// </synopsis>
56
57// <motivation>
58// Encapsulate Table locking data.
59// </motivation>
60
61
63{
64public:
65 // Construct from the given TableLock object.
66 ExternalLockSync (const TableLock& lockOptions);
67
69
70 // Copy constructor is forbidden.
71 ExternalLockSync (const ExternalLockSync& that) = delete;
72
73 // Assignment is forbidden.
75
76 // Create the <src>LockFile</src> object and acquire a read or write
77 // lock when permanent locking is in effect.
78 // It throws an exception when acquiring the lock failed.
79 void makeLock (const String& tableName, Bool create, FileLocker::LockType);
80
81 // Acquire a read or write lock (when needed).
82 // Nattempts==0 indicates that it has to wait until the lock is acquired.
83 // Nattempts>0 indicates that it gives up acquiring the lock when
84 // nattempts have been done (with 1 second intervals).
85 // It throws an exception when acquire failed while it had to wait.
86 // It returns a false status when acquiring the lock failed
87 // while it does not have to wait.
88 // <br>When a lock is successfully acquired, the number of rows
89 // (see function nrrow() below) is reset as a result of
90 // synchronizing the access to the table.
92
93 // Get the current number of rows in this object.
94 rownr_t nrow() const;
95
96 // Release the lock and synchronize the table access.
97 // When autolocking is in effect, the lock is only released when
98 // the inspection-interval (see class
99 // <linkto class=TableLockData>TableLockData</linkto>) has expired.
100 // It does nothing when permanent locking is used.
101 // It throws an exception when the release failed.
102 void release (rownr_t nrrow);
103
104 // Check if the table has a read or write lock, thus if the table can
105 // be read or written safely.
107
108private:
109 // The callback function when releasing a lock.
110 static MemoryIO* releaseCallBack (void* lockSyncObject, Bool always);
111
112 // The member function executing the callback functionality.
114
115
116 //# Define the lock and sync data objects.
120};
121
122
124{
125 return itsLock.hasLock (type);
126}
128{
129 itsNrrow = nrrow;
131}
138{
139 return itsNrrow;
140}
141
142
143
144} //# NAMESPACE CASACORE - END
145
146#endif
void makeLock(const String &tableName, Bool create, FileLocker::LockType)
Create the LockFile object and acquire a read or write lock when permanent locking is in effect.
void release(rownr_t nrrow)
Release the lock and synchronize the table access.
Bool acquire(FileLocker::LockType=FileLocker::Write, uInt nattempts=0)
Acquire a read or write lock (when needed).
MemoryIO * doReleaseCallBack(Bool always)
The member function executing the callback functionality.
Bool hasLock(FileLocker::LockType) const
Check if the table has a read or write lock, thus if the table can be read or written safely.
rownr_t nrow() const
Get the current number of rows in this object.
static MemoryIO * releaseCallBack(void *lockSyncObject, Bool always)
The callback function when releasing a lock.
ExternalLockSync(const ExternalLockSync &that)=delete
Copy constructor is forbidden.
ExternalLockSync(const TableLock &lockOptions)
Construct from the given TableLock object.
ExternalLockSync & operator=(const ExternalLockSync &that)=delete
Assignment is forbidden.
LockType
Define the possible lock types.
Definition FileLocker.h:93
@ Write
Acquire a write lock.
Definition FileLocker.h:97
String: the storage and methods of handling collections of characters.
Definition String.h:223
void release(Bool always=False)
Release the lock.
Bool hasLock(FileLocker::LockType) const
Has this process the read or write lock, thus can the table be read or written safely?
void write(rownr_t nrrow, uInt nrcolumn, Bool tableChanged, const Block< Bool > &dataManChanged)
Update the synchronization data and write it into the MemoryIO object.
MemoryIO & memoryIO()
Get the MemoryIO object.
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
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44