Obtain a read lock on a resource. This is only spin if there is a write lock in place.
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | hzLockRW::LockRead | (int32_t,) |
Declared in file: hzLock.h
Defined in file : hzLock.cpp
Function Logic:
Function body:
hzEcode hzLockRW::LockRead (int32_t timeout)
{
// Obtain a read lock on a resource. This is only spin if there is a write lock in place.
//
// Arguments: 1) timout The timeout limit (limit of retries in thousands)
//
// Returns: E_NOTFOUND The previous thread with write access killed the lock (should be because it deleted the applicable resource)
// E_TIMEOUT The thread holding write access has held the lock for too long
// E_OK Write access granted
_hzfunc("hzLockRW::LockRead") ;
uint32_t cont ; // Contention or spin count
uint32_t tid ; // Caller thread id
if (!_hzGlobal_MT)
return E_OK ;
tid = pthread_self() ;
if (m_lockval == 0xffffffff)
return E_NOTFOUND ;
if (m_lockval == tid)
Fatal("Attempt by thread %u to re-lock address %p\n", tid, &m_lockval) ;
// Spin until the lock is free (m_lockval == 0)
for (cont = 0; m_lockval ; cont++)
{
if (m_lockval == 0xffffffff)
return E_NOTFOUND ;
if (!m_lockval)
break ;
}
// Increment count of read locks obtained
while (__sync_add_and_fetch(&m_counter, 1));
return E_OK ;
}