casacore
Loading...
Searching...
No Matches
TableLockData.h
Go to the documentation of this file.
1// # TableLockData.h: Class to hold table lock data
2// # Copyright (C) 1997,1998,1999,2000,2002,2003
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_TABLELOCKDATA_H
27#define TABLES_TABLELOCKDATA_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/tables/Tables/TableLock.h>
32
33namespace casacore { // # NAMESPACE CASACORE - BEGIN
34
35// <summary>
36// Class to hold table lock data.
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>TableLock</linkto>
46// </prerequisite>
47
48// <synopsis>
49// This class keeps the <src>LockFile</src> object used to do the
50// actual locking/unlocking.
51// It also keeps the synchronization information.
52// </synopsis>
53
54// <motivation>
55// Encapsulate Table locking data.
56// </motivation>
57
58class TableLockData : public TableLock {
59 public:
60 // Define the signature of the callback function when a lock is released.
61 // The flag <src>always</src> tells if the callback function should
62 // always write its main data (meant for case that table gets closed).
63 // The callback function has to write the synchronization data
64 // (preferably in canonical format) in a MemoryIO object.
65 // A pointer to this MemoryIO object has to be returned. A zero pointer
66 // can be returned when no synchronization data is available.
67 typedef MemoryIO* ReleaseCallBack(void* parentObject, Bool always);
68
69 // Construct from the given TableLock object.
70 TableLockData(const TableLock& lockOptions, ReleaseCallBack* = 0, void* releaseParentObject = 0);
71
73
74 // Copy constructor is forbidden.
75 TableLockData(const TableLockData& that) = delete;
76
77 // Assignment is forbidden.
78 TableLockData& operator=(const TableLockData& that) = delete;
79
80 // Create the <src>LockFile</src> object and acquire a read or write
81 // lock when permanent locking is in effect.
82 // It throws an exception when acquiring the lock failed.
83 void makeLock(const String& name, Bool create, FileLocker::LockType, uInt locknr = 0);
84
85 // Acquire a read or write lock.
86 // It throws an exception when acquire failed while it had to wait.
88
89 // Release the lock. When always==False, the lock is not released
90 // when a permanent lock is used.
91 // It does nothing when permanent locking is used.
92 // It throws an exception when the release failed.
93 // When the lock is released, the release callback function (if defined)
94 // is called to write the synchronization data.
95 void release(Bool always = False);
96
97 // When the inspection interval has expired, inspect if another process
98 // needs the lock. If so, release the lock.
99 // <src>always=True</src> means that the inspection is always done,
100 // thus not every 25th call or so.
101 void autoRelease(Bool always = False);
102
103 // Has this process the read or write lock, thus can the table
104 // be read or written safely?
106
107 // Is the table in use (i.e. open) in another process?
108 Bool isMultiUsed() const;
109
110 // Get or put the info in the lock file.
111 // <group>
112 void getInfo(MemoryIO& info);
113 void putInfo(const MemoryIO& info);
114 // </group>
115
116 private:
117 // # Define the lock file.
119 // # Define if the file is already read or write locked.
122};
123
125 return (itsLock == 0 ? True : itsLock->hasLock(type));
126}
127inline void TableLockData::autoRelease(Bool always) {
128 if (option() == AutoLocking && itsLock->inspect(always)) {
129 release();
130 }
131}
132inline Bool TableLockData::isMultiUsed() const { return itsLock->isMultiUsed(); }
133
134inline void TableLockData::getInfo(MemoryIO& info) { itsLock->getInfo(info); }
135inline void TableLockData::putInfo(const MemoryIO& info) { itsLock->putInfo(info); }
136
137} // namespace casacore
138
139#endif
LockType
Define the possible lock types.
Definition FileLocker.h:89
String: the storage and methods of handling collections of characters.
Definition String.h:355
void autoRelease(Bool always=False)
When the inspection interval has expired, inspect if another process needs the lock.
void release(Bool always=False)
Release the lock.
void getInfo(MemoryIO &info)
Get or put the info in the lock file.
Bool acquire(MemoryIO *info, FileLocker::LockType, uInt nattempts)
Acquire a read or write lock.
MemoryIO * ReleaseCallBack(void *parentObject, Bool always)
Define the signature of the callback function when a lock is released.
ReleaseCallBack * itsReleaseCallBack
Bool isMultiUsed() const
Is the table in use (i.e.
void putInfo(const MemoryIO &info)
TableLockData(const TableLock &lockOptions, ReleaseCallBack *=0, void *releaseParentObject=0)
Construct from the given TableLock object.
void makeLock(const String &name, Bool create, FileLocker::LockType, uInt locknr=0)
Create the LockFile object and acquire a read or write lock when permanent locking is in effect.
TableLockData & operator=(const TableLockData &that)=delete
Assignment is forbidden.
TableLockData(const TableLockData &that)=delete
Copy constructor is forbidden.
Bool hasLock(FileLocker::LockType) const
Has this process the read or write lock, thus can the table be read or written safely?
@ AutoLocking
The system takes care of acquiring/releasing locks.
Definition TableLock.h:93
TableLock(LockOption option=DefaultLocking)
Construct with given option and interval.
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
const Bool False
Definition aipstype.h:42
unsigned int uInt
Definition aipstype.h:49
String name() const
Return the name of the field.
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41