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
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/tables/Tables/TableLock.h>
33
34
35namespace casacore { //# NAMESPACE CASACORE - BEGIN
36
37// <summary>
38// Class to hold table lock data.
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>TableLock</linkto>
48// </prerequisite>
49
50// <synopsis>
51// This class keeps the <src>LockFile</src> object used to do the
52// actual locking/unlocking.
53// It also keeps the synchronization information.
54// </synopsis>
55
56// <motivation>
57// Encapsulate Table locking data.
58// </motivation>
59
60
62{
63public:
64 // Define the signature of the callback function when a lock is released.
65 // The flag <src>always</src> tells if the callback function should
66 // always write its main data (meant for case that table gets closed).
67 // The callback function has to write the synchronization data
68 // (preferably in canonical format) in a MemoryIO object.
69 // A pointer to this MemoryIO object has to be returned. A zero pointer
70 // can be returned when no synchronization data is available.
71 typedef MemoryIO* ReleaseCallBack (void* parentObject, Bool always);
72
73 // Construct from the given TableLock object.
74 TableLockData (const TableLock& lockOptions, ReleaseCallBack* = 0,
75 void* releaseParentObject = 0);
76
78
79 // Copy constructor is forbidden.
80 TableLockData (const TableLockData& that) = delete;
81
82 // Assignment is forbidden.
83 TableLockData& operator= (const TableLockData& that) = delete;
84
85 // Create the <src>LockFile</src> object and acquire a read or write
86 // lock when permanent locking is in effect.
87 // It throws an exception when acquiring the lock failed.
88 void makeLock (const String& name, Bool create, FileLocker::LockType,
89 uInt locknr = 0);
90
91 // Acquire a read or write lock.
92 // It throws an exception when acquire failed while it had to wait.
94
95 // Release the lock. When always==False, the lock is not released
96 // when a permanent lock is used.
97 // It does nothing when permanent locking is used.
98 // It throws an exception when the release failed.
99 // When the lock is released, the release callback function (if defined)
100 // is called to write the synchronization data.
101 void release (Bool always = False);
102
103 // When the inspection interval has expired, inspect if another process
104 // needs the lock. If so, release the lock.
105 // <src>always=True</src> means that the inspection is always done,
106 // thus not every 25th call or so.
107 void autoRelease (Bool always=False);
108
109 // Has this process the read or write lock, thus can the table
110 // be read or written safely?
112
113 // Is the table in use (i.e. open) in another process?
114 Bool isMultiUsed() const;
115
116 // Get or put the info in the lock file.
117 // <group>
118 void getInfo (MemoryIO& info);
119 void putInfo (const MemoryIO& info);
120 // </group>
121
122private:
123 //# Define the lock file.
125 //# Define if the file is already read or write locked.
128};
129
130
132{
133 return (itsLock == 0 ? True : itsLock->hasLock (type));
134}
136{
137 if (option() == AutoLocking && itsLock->inspect(always)) {
138 release();
139 }
140}
142{
143 return itsLock->isMultiUsed();
144}
145
146
148{
149 itsLock->getInfo (info);
150}
151inline void TableLockData::putInfo (const MemoryIO& info)
152{
153 itsLock->putInfo (info);
154}
155
156
157
158} //# NAMESPACE CASACORE - END
159
160#endif
LockType
Define the possible lock types.
Definition FileLocker.h:93
Bool isMultiUsed()
Is the file associated with the LockFile object in use in another process?
Bool hasLock(FileLocker::LockType=FileLocker::Write) const
Test if the process has a lock for read or write on the file.
Definition LockFile.h:357
void putInfo(const MemoryIO &info) const
Put the info into the file (after the request id's).
Bool inspect(Bool always=False)
Inspect if another process wants to access the file (i.e.
void getInfo(MemoryIO &info)
Get the request id's and the info from the lock file.
String: the storage and methods of handling collections of characters.
Definition String.h:223
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:97
LockOption option() const
Get the locking option.
Definition TableLock.h:182
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
unsigned int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41