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 --- 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 collapse

VERSION =
"0.2.0"

Instance Method Summary collapse

Instance Method Details

#mu_extendedObject

:nodoc:



64
65
66
67
68
69
70
71
72
73
# 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_lockObject

See Thread::Mutex#lock



91
92
93
# File 'lib/mutex_m.rb', line 91

def mu_lock
  @_mutex.lock
end

#mu_locked?Boolean

See Thread::Mutex#locked?

Returns:

  • (Boolean)


81
82
83
# File 'lib/mutex_m.rb', line 81

def mu_locked?
  @_mutex.locked?
end

#mu_synchronize(&block) ⇒ Object

See Thread::Mutex#synchronize



76
77
78
# File 'lib/mutex_m.rb', line 76

def mu_synchronize(&block)
  @_mutex.synchronize(&block)
end

#mu_try_lockObject

See Thread::Mutex#try_lock



86
87
88
# File 'lib/mutex_m.rb', line 86

def mu_try_lock
  @_mutex.try_lock
end

#mu_unlockObject

See Thread::Mutex#unlock



96
97
98
# File 'lib/mutex_m.rb', line 96

def mu_unlock
  @_mutex.unlock
end

#sleep(timeout = nil) ⇒ Object

See Thread::Mutex#sleep



101
102
103
# File 'lib/mutex_m.rb', line 101

def sleep(timeout = nil)
  @_mutex.sleep(timeout)
end