CWin32ReadWriteLock Class Reference#include <Win32ReadWriteLock.h>
Inheritance diagram for CWin32ReadWriteLock:
![]()
Collaboration diagram for CWin32ReadWriteLock:
![]()
Detailed DescriptionDefinition at line 50 of file Win32ReadWriteLock.h. Constructor & Destructor Documentation
Definition at line 51 of file Win32ReadWriteLock.cpp. 00051 : CGenericReadWriteLock(iMaximumReaders), 00052 m_pSemaphore(NULL), 00053 m_pMutex(NULL), 00054 m_bWriter(FALSE), 00055 m_bEscalation(FALSE), 00056 m_iReaders(0) 00057 { 00058 //Allocate the mutex and the semaphores 00059 m_pMutex=COSManager::CreateMutex(); 00060 m_pSemaphore=COSManager::CreateSemaphore(iMaximumReaders,iMaximumReaders); 00061 }
Definition at line 63 of file Win32ReadWriteLock.cpp. 00064 { 00065 //Delete the mutexs and semaphores 00066 delete m_pMutex; 00067 delete m_pSemaphore; 00068 }
Member Function Documentation
Implements CGenericReadWriteLock. Definition at line 168 of file Win32ReadWriteLock.cpp. 00170 { 00171 //Try to lock for write 00172 if (LockWrite()) 00173 return TRUE; 00174 00175 //Try to escalate 00176 CMutexAutoRelease aRelease(m_pMutex,TRUE); 00177 00178 //Change the escalation status 00179 m_bEscalation=TRUE; 00180 00181 //Exit from the mutex 00182 aRelease.Release(); 00183 00184 //And wait to see if we can continue 00185 for (unsigned long ulCounter=0;ulCounter<ulIterations;++ulCounter) 00186 { 00187 //Can we write 00188 if (LockWrite()) 00189 return TRUE; 00190 00191 //Wait 00192 Sleep(ulMSTimeout); 00193 } 00194 00195 //Failed to escalate 00196 return FALSE; 00197 }
Implements CGenericReadWriteLock. Definition at line 70 of file Win32ReadWriteLock.cpp. 00071 { 00072 //First lock the mutex and check the read flag 00073 CMutexAutoRelease aRelease(m_pMutex,TRUE); 00074 00075 //Check the flag 00076 if (m_bEscalation || m_bWriter) 00077 //Can't lock 00078 return FALSE; 00079 00080 //Check if we will be locked ? 00081 if (m_iReaders==GetMaximumReaders()) 00082 { 00083 //Release the lock and try to get it 00084 aRelease.Release(); 00085 00086 //Lock the semaphore 00087 if (m_pSemaphore->Aquire(ulMSTimeout)) 00088 return FALSE; 00089 else 00090 { 00091 //Relock it 00092 aRelease.Aquire(); 00093 00094 //Check if there are writers ? 00095 if (m_bEscalation || m_bWriter) 00096 { 00097 //So soon ? 00098 //Release what we got 00099 m_pSemaphore->Release(); 00100 00101 //Exit 00102 return FALSE; 00103 } 00104 else 00105 //Increase the count 00106 ++m_iReaders; 00107 } 00108 } 00109 else if (m_pSemaphore->Aquire(ulMSTimeout)) 00110 return FALSE; 00111 else 00112 //Increase the semaphore and our count 00113 ++m_iReaders; 00114 00115 //Done 00116 return TRUE; 00117 }
Implements CGenericReadWriteLock. Definition at line 135 of file Win32ReadWriteLock.cpp. 00136 { 00137 //First lock the mutex and check the read flag 00138 CMutexAutoRelease aRelease(m_pMutex,TRUE); 00139 00140 //Check the flag 00141 if (m_iReaders || m_bWriter) 00142 //Can't lock 00143 return FALSE; 00144 00145 //Indicate we are writing 00146 m_bWriter=TRUE; 00147 00148 //Done 00149 return TRUE; 00150 }
Implements CGenericReadWriteLock. Definition at line 199 of file Win32ReadWriteLock.cpp. 00200 { 00201 //First lock the mutex and check the read flag 00202 CMutexAutoRelease aRelease(m_pMutex,TRUE); 00203 00204 //Remove escalation flag 00205 m_bEscalation=FALSE; 00206 }
Implements CGenericReadWriteLock. Definition at line 119 of file Win32ReadWriteLock.cpp. 00120 { 00121 //First lock the mutex and check the read flag 00122 CMutexAutoRelease aRelease(m_pMutex,TRUE); 00123 00124 //Do we have readers 00125 if (m_iReaders) 00126 { 00127 //Release the semaphore 00128 m_pSemaphore->Release(); 00129 00130 //Decrease the count 00131 --m_iReaders; 00132 } 00133 }
Implements CGenericReadWriteLock. Definition at line 152 of file Win32ReadWriteLock.cpp. 00153 { 00154 //First lock the mutex and check the read flag 00155 CMutexAutoRelease aRelease(m_pMutex,TRUE); 00156 00157 //Do we have readers 00158 if (m_bWriter) 00159 { 00160 //Not writing 00161 m_bWriter=FALSE; 00162 00163 //Remove escalation flag 00164 m_bEscalation=FALSE; 00165 } 00166 }
The documentation for this class was generated from the following files: |