From ef3d6958eab22069bc6d8e567e0b04c9aa4880a7 Mon Sep 17 00:00:00 2001 From: Marc Siegel Date: Mon, 30 Dec 2013 13:22:07 -0500 Subject: [PATCH] Slight refactor to share common code path and clarify behavior --- lib/process_shared/synchronizable_semaphore.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/process_shared/synchronizable_semaphore.rb b/lib/process_shared/synchronizable_semaphore.rb index f381b37..0a52873 100644 --- a/lib/process_shared/synchronizable_semaphore.rb +++ b/lib/process_shared/synchronizable_semaphore.rb @@ -45,11 +45,9 @@ module ProcessShared # @return [Boolean] +true+ if currently locked def locked? - @sem.try_wait - @sem.post - false - rescue Errno::EAGAIN - true + acquired = try_lock + unlock if acquired + !acquired end # Releases the lock and sleeps timeout seconds if it is given and