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