Class: ClimateControl::Environment

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/climate_control/environment.rb

Instance Method Summary collapse

Constructor Details

#initializeEnvironment

Returns a new instance of Environment.



7
8
9
10
# File 'lib/climate_control/environment.rb', line 7

def initialize
  @semaphore = Mutex.new
  @owner = nil
end

Instance Method Details

#synchronizeObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/climate_control/environment.rb', line 14

def synchronize
  if @owner == Thread.current
    return yield if block_given?
  end

  @semaphore.synchronize do
    @owner = Thread.current
    yield if block_given?
  ensure
    @owner = nil
  end
end