Method: ConcurrentSHM::Mutex#try_lock

Defined in:
ext/concurrent-shm/posix.c

#try_lockBoolean

Attempts to lock the mutex.

Returns:

  • (Boolean)

    true if the lock was acquired

Raises:

  • (Errno::EAGAIN)

    if the mutex could not be acquired because the maximum number of recursive locks for mutex has been exceeded



597
598
599
600
601
602
603
604
605
606
607
608
609
# File 'ext/concurrent-shm/posix.c', line 597

static VALUE mutex_try_lock(VALUE self)
{
    mutex_t * mu = value_as_mutex(self);
    int err = pthread_mutex_trylock(&mu->shared->mu);
    switch (err) {
    case 0:
        return Qtrue;
    case EBUSY:
        return Qfalse;
    default:
        rb_syserr_fail_strf(err, "mutex_try_lock");
    }
}