Mobile API Reference  MicroStrategy 2019
InprocessFileLocker.h
Go to the documentation of this file.
1 //==============================================================================================
2 // FILENAME : InprocessFileLocker.h
3 // AUTHOR : vovechkin
4 // CREATION : 2004-12-01
5 // Copyright (C) MicroStrategy Incorporated 2004
6 // All Rights Reserved
7 //==============================================================================================
8 #ifndef MFileSystem_InprocessFileLocker_h
9 #define MFileSystem_InprocessFileLocker_h
10 
11 #ifndef WIN32
12 
13 #include "PDCstat.h"
14 
16 #include "Base/Defines/SmartPtrI.h"
19 
20 #include "FileImpl.h"
21 
22 namespace MFileSystem
23 {
24  class ModuleMain;
25 
33  virtual public MBase::ReferenceCounted,
35  {
36  public:
37 
38 // typedef MBase::SmartPtrI<InprocessFileLocker> Ptr;
40 
41  class LockPtr:
42  protected MBase::SmartPtrI<InprocessFileLocker>
43  {
44  public:
45 
46  // default constructor
49  {
50  }
51 
52  // destructor
54  {
55  if (IsNull() == false)
56  {
57  Get()->Unlock();
58  }
59  }
60 
61  // assignment
62 #if defined(__IBMCPP__) || defined(WIN64) || defined(__GNUG__)
63  LockPtr& operator=(const MBase::ReturnPtrI<InprocessFileLocker>& irReturnPtr) throw()
64 #else
66 #endif
67  {
68  if (IsNull() == false)
69  {
70  Get()->Unlock();
71  }
72 
73  MBase::SmartPtrI<InprocessFileLocker>* lpBaseClass = this;
74  lpBaseClass->operator=(irReturnPtr);
75 
76  if (IsNull() == false)
77  {
78  Get()->Lock();
79  }
80 
81  return *this;
82  }
83 
84 #if defined(__IBMCPP__) || defined(WIN64) || defined(__GNUG__)
85  LockPtr& Assign(const MBase::ReturnPtrI<InprocessFileLocker>& irReturnPtr,bool bInProcessLock_NoWait=false)
86 #else
87  LockPtr& Assign(MBase::ReturnPtrI<InprocessFileLocker>& irReturnPtr,bool bInProcessLock_NoWait=false)
88 #endif
89  {
90  if (IsNull() == false)
91  {
92  Get()->Unlock();
93  }
94 
95  MBase::SmartPtrI<InprocessFileLocker>* lpBaseClass = this;
96  lpBaseClass->operator=(irReturnPtr);
97 
98  if (IsNull() == false)
99  {
100  if (bInProcessLock_NoWait)
101  {
102  bool lbReturn = Get()->LockWithTimeOut();
103  if (!lbReturn)
104  throw ("MFileSystem::InprocessFileLocker::LockPtr::Assign() failed to get the InprocessLock");
105 
106  }
107  else
108  Get()->Lock();
109  }
110 
111  return *this;
112  }
113  // accessor
115  {
117  }
118 
119  void Reset() throw()
120  {
121  if (IsNull() == false)
122  {
123  Get()->Unlock();
124  }
125 
127  }
128  };
129 
134  class ID
135  {
136  public:
137 
138  ID(const char* ipFilePath, FileHandle iFileHandle);
139 
140  inline bool operator<(const ID& iOtherID) const;
141 
142  private:
143 
144  dev_t mDevice;
145  ino_t mInode;
146  };
147 
148  InprocessFileLocker(const ID& irID, ModuleMain* ipModuleMain);
149  virtual ~InprocessFileLocker() throw();
150 
151  inline const ID& GetID() const throw();
152 
153  protected:
154 
155  friend class LockPtr;
156  void Lock();
157  bool LockWithTimeOut();
158  void Unlock() throw();
159 
160  protected:
161 
163  virtual void ReferenceCountIsAboutToReachZero() const throw();
164 
165  public:
166  virtual void Release() const throw();
167  void parentRelease() const throw()
168  {
170  }
171 
172  private:
173 
174  ModuleMain* mpModuleMain;
175  const ID mID;
176 
177  MSynch::InprocessSemaphore mSemaphore;
178  };
179 }
180 
181 inline bool MFileSystem::InprocessFileLocker::ID::operator<(const ID& iOtherID) const
182 {
183  if (mDevice == iOtherID.mDevice)
184  {
185  return (mInode < iOtherID.mInode);
186  }
187  else
188  {
189  return (mDevice < iOtherID.mDevice);
190  }
191 }
192 
194 {
195  return mID;
196 }
197 
198 #endif // WIN32
199 #endif // MFileSystem_InprocessFileLocker_h
InprocessFileLocker * operator->() const
Definition: InprocessFileLocker.h:114
LockPtr & Assign(MBase::ReturnPtrI< InprocessFileLocker > &irReturnPtr, bool bInProcessLock_NoWait=false)
Definition: InprocessFileLocker.h:87
const ID & GetID() const
Definition: InprocessFileLocker.h:193
~LockPtr()
Definition: InprocessFileLocker.h:53
void parentRelease() const
Definition: InprocessFileLocker.h:167
bool IsNull() const
Definition: SmartPtrI.h:204
InprocessFileLocker(const ID &irID, ModuleMain *ipModuleMain)
void Reset(ReferenceCountedT *ipData=NULL)
Definition: SmartPtrI.h:102
LockPtr & operator=(MBase::ReturnPtrI< InprocessFileLocker > &irReturnPtr)
Definition: InprocessFileLocker.h:65
InprocessFileLocker * Get() const
Definition: SmartPtrI.h:199
Definition: InprocessFileLocker.h:41
virtual void Release() const
Definition: FileSystem/FileSystem/PrivateSource/ModuleMain.h:24
Definition: Allocator.h:47
virtual void ReferenceCountIsAboutToReachZero() const
ID(const char *ipFilePath, FileHandle iFileHandle)
Definition: ReturnPtrI.h:47
LockPtr()
Definition: InprocessFileLocker.h:47
SmartPtrI(InprocessFileLocker *ipData=NULL)
Definition: SmartPtrI.h:38
Definition: InprocessSemaphore.h:18
Definition: InprocessFileLocker.h:134
Definition: ReferenceCountedImpl.h:44
bool operator<(const ID &iOtherID) const
Definition: InprocessFileLocker.h:181
int FileHandle
Definition: FileImpl.h:21
MBase::ReturnPtrI< InprocessFileLocker > ReturnPtr
Definition: InprocessFileLocker.h:39
Definition: StrongObjects.h:21
Definition: InprocessFileLocker.h:32
ReferenceCountedT * operator->() const
Definition: SmartPtrI.h:187
virtual void Release() const
Definition: ReferenceCountedImpl.h:64
Definition: ReturnPtrI.h:22
void Reset()
Definition: InprocessFileLocker.h:119
Definition: ReferenceCounted.h:58