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.



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

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

Instance Method Details

#synchronizeObject



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

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

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