try_lock()
public
Attempts to obtain the lock and returns
immediately. Returns true if the lock was granted.
Show source
VALUE
rb_mutex_trylock(VALUE self)
{
mutex_t *mutex;
VALUE locked = Qfalse;
GetMutexPtr(self, mutex);
native_mutex_lock(&mutex->lock);
if (mutex->th == 0) {
mutex->th = GET_THREAD();
locked = Qtrue;
mutex_locked(GET_THREAD(), self);
}
native_mutex_unlock(&mutex->lock);
return locked;
}