| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | hzLockRWD::LockWrite | (int,) |
Declared in file: hzLock.h
Defined in file : hzLock.cpp
Function Logic:
Function body:
hzEcode hzLockRWD::LockWrite (int timeout)
{
_hzfunc("hzLockRWD::LockWrite") ;
uint64_t now ;
uint64_t got ;
uint32_t cont ;
uint32_t tries ;
uint32_t tid ;
uint32_t limit ;
if (!_hzGlobal_MT)
return E_OK ;
now = RealtimeNano() ;
tid = pthread_self() ;
limit = timeout < 0? 0xfffffffe:timeout*1000;
if (m_lockval == tid)
{
m_recurse++ ;
m_LockOpsW++ ;
m_SpinsThis = 0;
return E_OK ;
}
for (tries = cont = 0;;)
{
if (m_lockval)
{
cont++ ;
continue ;
}
if (!__sync_val_compare_and_swap(&(m_lockval), 0,tid))
{
if (m_lockval == tid)
break ;
}
tries++ ;
if (tries > limit)
return E_TIMEOUT ;
}
for (; m_counter ; cont++) ;
m_lockval = tid ;
m_recurse = 0;
m_LockOpsW++ ;
m_TriesThis = tries ;
m_TriesTotal += tries ;
m_SpinsThis = cont ;
m_SpinsTotal += cont ;
got = RealtimeNano() ;
m_Granted = got ;
m_WaitThis = (got - now) ;
m_WaitTotal += m_WaitThis ;
return E_OK ;
}