Home

Traffic Server Software Developers Kit

INKMutexLockTry

Tries to lock an INKMutex.

Prototype

INKReturnCode InkMutexLockTry (INKMutex mutex, int *lock)

Description

Tries to lock the INKMutex mutex. Information about whether the lock was grabbed is set in int *lock. INKReturnCode tells you if the call was successful or not, but does not indicate if the lock was grabbed.

In general, use InkMutexLockTry to obtain a mutex (see the example below).

Returns

If the mutex was successfully locked, then 1 is returned.

If mutex is already locked, then 0 is returned.

Example
int handler (INKCont contp, INKEvent event, void *edata)
{
   //This continuation tries to grab a mutex
   int retval, lock = 0;
retvak = InkMutexLockTry (mutex, &lock);
   if (!lock)
   {
   /* Schedule a retry; RETRY_TIME should be 10 ms or longer. */
      INKContSchedule (contp, RETRY_TIME); 
      return INK_EVENT_IMMEDIATE;
   }

   // Now the mutex has been grabbed
   do_some_job ...
   INKMutexUnlock (mutexp);
}