Module: Mutex_m
| Relationships & Source Files | |
| Defined in: | lib/mutex_m.rb | 
Overview
mutex_m.rb
When ‘mutex_m’ is required, any object that extends or includes Mutex_m will be treated like a Mutex.
Start by requiring the standard library Mutex_m:
require "mutex_m.rb"
From here you can extend an object with Mutex instance methods:
obj = Object.new
obj.extend Mutex_m
Or mixin Mutex_m into your module to your class inherit Mutex instance methods — remember to call super() in your class initialize method.
class Foo
  include Mutex_m
  def initialize
    # ...
    super()
  end
  # ...
end
obj = Foo.new
# this obj can be handled like Mutex
  Constant Summary
- 
    VERSION =
    
# File 'lib/mutex_m.rb', line 43"0.2.0" 
Class Method Summary
- .append_features(cl) Internal use only
 - .define_aliases(cl) Internal use only
 - .extend_object(obj) Internal use only
 
Instance Attribute Summary
- 
    
      #mu_locked?  ⇒ Boolean 
    
    readonly
    
See
Thread::Mutex#locked? 
Instance Method Summary
- 
    
      #mu_lock  
    
    
See
Thread::Mutex#lock - 
    
      #mu_synchronize(&block)  
    
    
See
Thread::Mutex#synchronize - 
    
      #mu_try_lock  
    
    
See
Thread::Mutex#try_lock - 
    
      #mu_unlock  
    
    
See
Thread::Mutex#unlock - 
    
      #sleep(timeout = nil)  
    
    
See
Thread::Mutex#sleep - #mu_extended Internal use only
 - #initialize(*args) private Internal use only
 - #mu_initialize private Internal use only
 
Class Method Details
.append_features(cl)
    This method is for internal use only.
  
  [ GitHub ]
# File 'lib/mutex_m.rb', line 54
def Mutex_m.append_features(cl) # :nodoc: super define_aliases(cl) unless cl.instance_of?(Module) end
.define_aliases(cl)
    This method is for internal use only.
  
  [ GitHub ]
# File 'lib/mutex_m.rb', line 46
def Mutex_m.define_aliases(cl) # :nodoc: cl.alias_method(:locked?, :mu_locked?) cl.alias_method(:lock, :mu_lock) cl.alias_method(:unlock, :mu_unlock) cl.alias_method(:try_lock, :mu_try_lock) cl.alias_method(:synchronize, :mu_synchronize) end
.extend_object(obj)
    This method is for internal use only.
  
  [ GitHub ]
# File 'lib/mutex_m.rb', line 59
def Mutex_m.extend_object(obj) # :nodoc: super obj.mu_extended end
Instance Attribute Details
    #mu_locked?  ⇒ Boolean  (readonly)
  
See Thread::Mutex#locked?
# File 'lib/mutex_m.rb', line 81
def mu_locked? @_mutex.locked? end
Instance Method Details
#initialize(*args) (private)
    This method is for internal use only.
  
  [ GitHub ]
# File 'lib/mutex_m.rb', line 111
def initialize(*args) # :nodoc: mu_initialize super end
#mu_extended
    This method is for internal use only.
  
  [ GitHub ]
# File 'lib/mutex_m.rb', line 64
def mu_extended # :nodoc: unless (defined? locked? and defined? lock and defined? unlock and defined? try_lock and defined? synchronize) Mutex_m.define_aliases(singleton_class) end mu_initialize end
#mu_initialize (private)
    This method is for internal use only.
  
  [ GitHub ]
# File 'lib/mutex_m.rb', line 107
def mu_initialize # :nodoc: @_mutex = Thread::Mutex.new end
#mu_lock
See Thread::Mutex#lock
# File 'lib/mutex_m.rb', line 91
def mu_lock @_mutex.lock end
#mu_synchronize(&block)
See Thread::Mutex#synchronize
# File 'lib/mutex_m.rb', line 76
def mu_synchronize(&block) @_mutex.synchronize(&block) end
#mu_try_lock
See Thread::Mutex#try_lock
# File 'lib/mutex_m.rb', line 86
def mu_try_lock @_mutex.try_lock end
#mu_unlock
See Thread::Mutex#unlock
# File 'lib/mutex_m.rb', line 96
def mu_unlock @_mutex.unlock end
#sleep(timeout = nil)
See Thread::Mutex#sleep
# File 'lib/mutex_m.rb', line 101
def sleep(timeout = nil) @_mutex.sleep(timeout) end