Home

Traffic Server Software Developers Kit

Mutex Function

InkMutexTryLock

Tries to lock an INKMutex.

Prototype

INKReturnCode InkMutexTryLock (INKMutex mutex, int *is_mutex_lock)

Description

Tries to lock the INKMutex mutex.

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

This API has been deprecated by INKMutexLockTry.

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 lock = InkMutexTryLock (mutex);
   if (!lock)
   {
   /* Schedule a retry; RETRY_TIME should be 10 ms or longer. */
      INKContSchedule (contp, RETRY_TIME); 
      return INK_EVENT_IMMEDIATE;
   }

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