Class: Farce::Lock
- Inherits:
-
Internal::Lock
- Object
- Internal::Lock
- Farce::Lock
- Includes:
- Internal::Copyable, Shareable::Native, Shareable::Unfreezable, Internal::MarshalSupport::Reject
- Defined in:
- lib/farce/lock.rb
Overview
On JRuby and TruffleRuby, this will be a subclass of Mutex. On CRuby, it will be a custom implementation, as Mutex instances are not Ractor-shareable.
A Ractor-shareable mutual-exclusion lock with the same interface as Ruby's Mutex.
Lock ownership belongs to the current Fiber. Attempting to lock the same lock recursively raises ThreadError. Waiting for a lock cooperates with an installed Fiber scheduler.
Instance Method Summary collapse
-
#lock ⇒ self
Acquire the lock, waiting until it is available.
-
#locked? ⇒ Boolean
Whether any Fiber owns the lock.
-
#owned? ⇒ Boolean
Whether the current Fiber owns the lock.
-
#sleep(timeout = nil) ⇒ nil
Release the lock while sleeping, then reacquire it before returning.
-
#synchronize { ... } ⇒ Object
Acquire the lock for the duration of the block.
-
#try_lock ⇒ Boolean
Attempt to acquire the lock without waiting.
-
#unlock ⇒ self
Release the lock.
Methods included from Shareable
#initialize, #ractor_shareable?
Methods included from Internal::Copyable
Instance Method Details
#lock ⇒ self
Acquire the lock, waiting until it is available.
46 47 48 49 50 51 52 53 |
# File 'lib/farce/lock.rb', line 46 class Lock < Internal::Lock include Internal::MarshalSupport::Reject include Internal::Copyable include Shareable::Native include Shareable::Unfreezable private def instance_variables_to_inspect = Internal::EMPTY_ARRAY end |
#locked? ⇒ Boolean
Returns whether any Fiber owns the lock.
46 47 48 49 50 51 52 53 |
# File 'lib/farce/lock.rb', line 46 class Lock < Internal::Lock include Internal::MarshalSupport::Reject include Internal::Copyable include Shareable::Native include Shareable::Unfreezable private def instance_variables_to_inspect = Internal::EMPTY_ARRAY end |
#owned? ⇒ Boolean
Returns whether the current Fiber owns the lock.
46 47 48 49 50 51 52 53 |
# File 'lib/farce/lock.rb', line 46 class Lock < Internal::Lock include Internal::MarshalSupport::Reject include Internal::Copyable include Shareable::Native include Shareable::Unfreezable private def instance_variables_to_inspect = Internal::EMPTY_ARRAY end |
#sleep(timeout = nil) ⇒ nil
Release the lock while sleeping, then reacquire it before returning.
46 47 48 49 50 51 52 53 |
# File 'lib/farce/lock.rb', line 46 class Lock < Internal::Lock include Internal::MarshalSupport::Reject include Internal::Copyable include Shareable::Native include Shareable::Unfreezable private def instance_variables_to_inspect = Internal::EMPTY_ARRAY end |
#synchronize { ... } ⇒ Object
Acquire the lock for the duration of the block.
46 47 48 49 50 51 52 53 |
# File 'lib/farce/lock.rb', line 46 class Lock < Internal::Lock include Internal::MarshalSupport::Reject include Internal::Copyable include Shareable::Native include Shareable::Unfreezable private def instance_variables_to_inspect = Internal::EMPTY_ARRAY end |
#try_lock ⇒ Boolean
Attempt to acquire the lock without waiting.
46 47 48 49 50 51 52 53 |
# File 'lib/farce/lock.rb', line 46 class Lock < Internal::Lock include Internal::MarshalSupport::Reject include Internal::Copyable include Shareable::Native include Shareable::Unfreezable private def instance_variables_to_inspect = Internal::EMPTY_ARRAY end |
#unlock ⇒ self
Release the lock.
46 47 48 49 50 51 52 53 |
# File 'lib/farce/lock.rb', line 46 class Lock < Internal::Lock include Internal::MarshalSupport::Reject include Internal::Copyable include Shareable::Native include Shareable::Unfreezable private def instance_variables_to_inspect = Internal::EMPTY_ARRAY end |