Release a lock on a resource. This could be either a write lock where the lock value equals the thread id of the calling thread, or a read lock where it does not. If the lock value equals this thread id, this thread has the write lock and the action is simply to release it and return. There is no need to use a sync function to do this as no other thread can have write access and no need to check the counter as no other thread can obtain read access while any thread has the write lock. If the lock value does not equal this thread id this thread only has a read lock so the action is only to decrement the lock using sync. The counter is checked beforehand to see if it is already zero. The program is terminated if the lock is already zero. Arguments: None Returns: None
| Return Type | Function name | Arguments |
|---|---|---|
| void | hzLockRW::Unlock | (void) |
Declared in file: hzLock.h
Defined in file : hzLock.cpp
Function Logic:
Function body:
void hzLockRW::Unlock (void)
{
// Release a lock on a resource. This could be either a write lock where the lock value equals the thread id of the calling thread, or a read lock where it
// does not. If the lock value equals this thread id, this thread has the write lock and the action is simply to release it and return. There is no need to
// use a sync function to do this as no other thread can have write access and no need to check the counter as no other thread can obtain read access while
// any thread has the write lock.
//
// If the lock value does not equal this thread id this thread only has a read lock so the action is only to decrement the lock using sync. The counter is
// checked beforehand to see if it is already zero. The program is terminated if the lock is already zero.
//
// Arguments: None
// Returns: None
_hzfunc("hzLockRWD::Unlock") ;
uint32_t tid ; // Caller thread id
if (_hzGlobal_MT)
{
if (m_lockval == 0xffffffff)
hzexit(E_CORRUPT, "Attempting to unlock a deprecated lock") ;
tid = pthread_self() ;
if (m_lockval == tid)
{
// This thread has the write lock so just release it
m_lockval = 0;
}
else
{
// Assume a read lock decrement counter but do nothing if the lock has been killed
if (m_lockval != 0xffffffff)
{
if (m_counter == 0)
hzexit(E_CORRUPT, "Lock count already zero") ;
while (__sync_add_and_fetch(&m_counter, -1));
}
}
}
}