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:
50 51 52 53 |
# File 'lib/mutex_m.rb', line 50 def Mutex_m.append_features(cl) # :nodoc: super define_aliases(cl) unless cl.instance_of?(Module) end |
.define_aliases(cl) ⇒ Object
:nodoc:
40 41 42 43 44 45 46 47 48 |
# File 'lib/mutex_m.rb', line 40 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:
55 56 57 58 |
# File 'lib/mutex_m.rb', line 55 def Mutex_m.extend_object(obj) # :nodoc: super obj.mu_extended end |
Instance Method Details
#mu_extended ⇒ Object
:nodoc:
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/mutex_m.rb', line 60 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
87 88 89 |
# File 'lib/mutex_m.rb', line 87 def mu_lock @_mutex.lock end |
#mu_locked? ⇒ Boolean
See Mutex#locked?
77 78 79 |
# File 'lib/mutex_m.rb', line 77 def mu_locked? @_mutex.locked? end |
#mu_synchronize(&block) ⇒ Object
See Mutex#synchronize
72 73 74 |
# File 'lib/mutex_m.rb', line 72 def mu_synchronize(&block) @_mutex.synchronize(&block) end |
#mu_try_lock ⇒ Object
See Mutex#try_lock
82 83 84 |
# File 'lib/mutex_m.rb', line 82 def mu_try_lock @_mutex.try_lock end |
#mu_unlock ⇒ Object
See Mutex#unlock
92 93 94 |
# File 'lib/mutex_m.rb', line 92 def mu_unlock @_mutex.unlock end |
#sleep(timeout = nil) ⇒ Object
See Mutex#sleep
97 98 99 |
# File 'lib/mutex_m.rb', line 97 def sleep(timeout = nil) @_mutex.sleep(timeout) end |