casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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: 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_EXTERNALLOCKSYNC_H
29 #define TABLES_EXTERNALLOCKSYNC_H
30 
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
36 
37 
38 namespace casacore { //# NAMESPACE CASACORE - BEGIN
39 
40 // <summary>
41 // Class to hold table lock data.
42 // </summary>
43 
44 // <use visibility=local>
45 
46 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="tTable" demos="">
47 // </reviewed>
48 
49 // <prerequisite>
50 // <li> class <linkto class=Table>TableLock</linkto>
51 // </prerequisite>
52 
53 // <synopsis>
54 // This class keeps the <src>LockFile</src> object used to do the
55 // actual locking/unlocking.
56 // It also keeps the synchronization information.
57 // </synopsis>
58 
59 // <motivation>
60 // Encapsulate Table locking data.
61 // </motivation>
62 
63 
65 {
66 public:
67  // Construct from the given TableLock object.
68  ExternalLockSync (const TableLock& lockOptions);
69 
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  // Copy constructor is forbidden.
106  ExternalLockSync (const ExternalLockSync& that);
107 
108  // Assignment is forbidden.
110 
111  // The callback function when releasing a lock.
112  static MemoryIO* releaseCallBack (void* lockSyncObject, Bool always);
113 
114  // The member function executing the callback functionality.
115  MemoryIO* doReleaseCallBack (Bool always);
116 
117 
118  //# Define the lock and sync data objects.
122 };
123 
124 
126 {
127  return itsLock.hasLock (type);
128 }
130 {
131  itsNrrow = nrrow;
132  itsLock.release();
133 }
135 {
137  return &(itsSync.memoryIO());
138 }
140 {
141  return itsNrrow;
142 }
143 
144 
145 
146 } //# NAMESPACE CASACORE - END
147 
148 #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...
Bool hasLock(FileLocker::LockType) const
Has this process the read or write lock, thus can the table be read or written safely?
Class to hold table synchronization data.
Definition: TableSyncData.h:78
rownr_t nrow() const
Get the current number of rows in this object.
Class to hold table lock data.
Definition: TableLockData.h:63
void write(rownr_t nrrow, uInt nrcolumn, Bool tableChanged, const Block< Bool > &dataManChanged)
Update the synchronization data and write it into the MemoryIO object.
void release(rownr_t nrrow)
Release the lock and synchronize the table access.
ExternalLockSync & operator=(const ExternalLockSync &that)
Assignment is forbidden.
MemoryIO & memoryIO()
Get the MemoryIO object.
ExternalLockSync(const TableLock &lockOptions)
Construct from the given TableLock object.
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...
Acquire a write lock.
Definition: FileLocker.h:99
MemoryIO * doReleaseCallBack(Bool always)
The member function executing the callback functionality.
Class to hold table lock data.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Bool acquire(FileLocker::LockType=FileLocker::Write, uInt nattempts=0)
Acquire a read or write lock (when needed).
Class to hold table lock options.
Definition: TableLock.h:68
uInt64 rownr_t
Define the type of a row number in a table.
Definition: aipsxtype.h:46
void release(Bool always=False)
Release the lock.
String: the storage and methods of handling collections of characters.
Definition: String.h:225
Class for IO to a memory buffer.
Definition: MemoryIO.h:124
static MemoryIO * releaseCallBack(void *lockSyncObject, Bool always)
The callback function when releasing a lock.
LockType
Define the possible lock types.
Definition: FileLocker.h:95
unsigned int uInt
Definition: aipstype.h:51