Module: Mutex_m

Defined in:
lib/mutex_m.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.append_features(cl) ⇒ Object



39
40
41
42
# File 'lib/mutex_m.rb', line 39

def Mutex_m.append_features(cl)
  super
  define_aliases(cl) unless cl.instance_of?(Module)
end

.define_aliases(cl) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/mutex_m.rb', line 29

def Mutex_m.define_aliases(cl)
  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



44
45
46
47
# File 'lib/mutex_m.rb', line 44

def Mutex_m.extend_object(obj)
  super
  obj.mu_extended
end

Instance Method Details

#mu_extendedObject



49
50
51
52
53
54
55
56
57
58
# File 'lib/mutex_m.rb', line 49

def mu_extended
  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



73
74
75
# File 'lib/mutex_m.rb', line 73

def mu_lock
  @_mutex.lock
end

#mu_locked?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/mutex_m.rb', line 65

def mu_locked?
  @_mutex.locked?
end

#mu_synchronize(&block) ⇒ Object

locking



61
62
63
# File 'lib/mutex_m.rb', line 61

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

#mu_try_lockObject



69
70
71
# File 'lib/mutex_m.rb', line 69

def mu_try_lock
  @_mutex.try_lock
end

#mu_unlockObject



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

def mu_unlock
  @_mutex.unlock
end