Module: Mutex_m
- 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.
class Foo
include Mutex_m
# ...
end
obj = Foo.new
# this obj can be handled like Mutex
Class Method Summary collapse
-
.append_features(cl) ⇒ Object
:nodoc:.
-
.define_aliases(cl) ⇒ Object
:nodoc:.
-
.extend_object(obj) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#mu_extended ⇒ Object
:nodoc:.
-
#mu_lock ⇒ Object
See Mutex#lock.
-
#mu_locked? ⇒ Boolean
See Mutex#locked?.
-
#mu_synchronize(&block) ⇒ Object
See Mutex#synchronize.
-
#mu_try_lock ⇒ Object
See Mutex#try_lock.
-
#mu_unlock ⇒ Object
See Mutex#unlock.
-
#sleep(timeout = nil) ⇒ Object
See Mutex#sleep.
Class Method Details
.append_features(cl) ⇒ Object
:nodoc:
51 52 53 54 |
# File 'lib/mutex_m.rb', line 51 def Mutex_m.append_features(cl) # :nodoc: super define_aliases(cl) unless cl.instance_of?(Module) end |
.define_aliases(cl) ⇒ Object
:nodoc:
41 42 43 44 45 46 47 48 49 |
# File 'lib/mutex_m.rb', line 41 def Mutex_m.define_aliases(cl) # :nodoc: cl.module_eval %q{ alias locked? mu_locked? alias lock mu_lock alias unlock mu_unlock alias try_lock mu_try_lock alias synchronize mu_synchronize } end |
.extend_object(obj) ⇒ Object
:nodoc:
56 57 58 59 |
# File 'lib/mutex_m.rb', line 56 def Mutex_m.extend_object(obj) # :nodoc: super obj.mu_extended end |
Instance Method Details
#mu_extended ⇒ Object
:nodoc:
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/mutex_m.rb', line 61 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_lock ⇒ Object
See Mutex#lock
88 89 90 |
# File 'lib/mutex_m.rb', line 88 def mu_lock @_mutex.lock end |
#mu_locked? ⇒ Boolean
See Mutex#locked?
78 79 80 |
# File 'lib/mutex_m.rb', line 78 def mu_locked? @_mutex.locked? end |
#mu_synchronize(&block) ⇒ Object
See Mutex#synchronize
73 74 75 |
# File 'lib/mutex_m.rb', line 73 def mu_synchronize(&block) @_mutex.synchronize(&block) end |
#mu_try_lock ⇒ Object
See Mutex#try_lock
83 84 85 |
# File 'lib/mutex_m.rb', line 83 def mu_try_lock @_mutex.try_lock end |
#mu_unlock ⇒ Object
See Mutex#unlock
93 94 95 |
# File 'lib/mutex_m.rb', line 93 def mu_unlock @_mutex.unlock end |
#sleep(timeout = nil) ⇒ Object
See Mutex#sleep
98 99 100 |
# File 'lib/mutex_m.rb', line 98 def sleep(timeout = nil) @_mutex.sleep(timeout) end |