Class: Multiton::InstanceMutex

Inherits:
Hash
  • Object
show all
Defined in:
lib/multiton.rb

Overview

Mutex to safely store multiton instances.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeInstanceMutex

:nodoc:



156
157
158
# File 'lib/multiton.rb', line 156

def initialize
  @global = Mutex.new
end

Class Method Details

.synchronizeObject



164
165
166
# File 'lib/multiton.rb', line 164

def (DummyMutex = Object.new).synchronize
  yield
end

Instance Method Details

#default(arg) ⇒ Object



168
169
170
# File 'lib/multiton.rb', line 168

def default(arg)
  @global.synchronize{ fetch(arg){ store(arg, Mutex.new) } }
end

#initialized(arg) ⇒ Object



160
161
162
# File 'lib/multiton.rb', line 160

def initialized(arg)
  store(arg, DummyMutex)
end