Obtain a lock on a resource. This will spin until either the lock is granted or the lock is deactivated (host entity destructed) Note: This will return E_OK immeadiately if _hzGlobal_MT is false (the program is single threaded)

Return TypeFunction nameArguments
hzEcodehzLockS::Lock(int32_t,)

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

Function Logic:

0:START 1:unknown 2:Return E_OK 3:tid items 4:unknown 5:items 6:unknown 7:unknown 8:Return E_NOTFOUND 9:unknown 10:items 11:unknown 12:unknown 13:items 14:unknown 15:Return E_TIMEOUT 16:m_lockval 17:Return E_OK

Function body:

hzEcode hzLockS::Lock (int32_t nTries)
{
   //  Obtain a lock on a resource. This will spin until either the lock is granted or the lock is deactivated (host entity destructed)
   //  
   //  Arguments: 1) nTries Number of retries (in thousands) before abandoning efforts to obtain the lock
   //  
   //  Returns: E_NOTFOUND If the lock has been killed by a previous holder
   //     E_TIMEOUT If the lock has not been release within nTries
   //     E_OK  If the lock is granted
   //  
   //  Note: This will return E_OK immeadiately if _hzGlobal_MT is false (the program is single threaded)
   uint32_t    cont ;      //  Contention or spin count
   uint32_t    tries ;     //  Contention or spin count
   uint32_t    tid ;       //  Thread id
   uint32_t    limit ;     //  Timeout as number of tries
   if (!_hzGlobal_MT)
       return E_OK ;
   tid = pthread_self() ;
   limit = nTries < 0? 0xfffffffe:nTries*1000;
   if (m_lockval == tid)
       Fatal("hzLockS::hzLockS. Attempt by thread %u to re-lock address %p\n", tid, &m_lockval) ;
   for (tries = cont = 0;;)
   {
       if (m_lockval == 0xffffffff)
           return E_NOTFOUND ;
       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 ;
   }
   m_lockval = tid ;
   return E_OK ;
}