Return TypeFunction nameArguments
hzEcodehzLockRWD::LockWrite(int,)

Declared in file: hzLock.h
Defined in file : hzLock.cpp

Function Logic:

0:START 1:!_hzGlobal_MT 2:Return E_OK 3:RealtimeNano now pthread_self tid limit 4:m_lockval==tid 5:items items m_SpinsThis 6:Return E_OK 7:; 8:m_lockval 9:items 10:!__sync_val_compare_and_swap(&(m_lockval),0,tid) 11:m_lockval==tid 12:items 13:tries>limit 14:Return E_TIMEOUT 15:m_counter; 16:m_lockval m_recurse items m_TriesThis m_TriesTotal m_SpinsThis m_SpinsTotal RealtimeNano got m_Granted m_WaitThis m_WaitTotal 17:Return E_OK

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 ;
}