Class: PhusionPassenger::AnalyticsLogger::Lock

Inherits:
Object
  • Object
show all
Defined in:
lib/phusion_passenger/analytics_logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(mutex) ⇒ Lock

Returns a new instance of Lock.



342
343
344
345
# File 'lib/phusion_passenger/analytics_logger.rb', line 342

def initialize(mutex)
	@mutex = mutex
	@locked = false
end

Instance Method Details

#lockObject



362
363
364
365
366
# File 'lib/phusion_passenger/analytics_logger.rb', line 362

def lock
	raise if @locked
	@mutex.lock
	@locked = true
end

#reset(mutex, lock_now = true) ⇒ Object



347
348
349
350
351
# File 'lib/phusion_passenger/analytics_logger.rb', line 347

def reset(mutex, lock_now = true)
	unlock if @locked
	@mutex = mutex
	lock if lock_now
end

#synchronizeObject



353
354
355
356
357
358
359
360
# File 'lib/phusion_passenger/analytics_logger.rb', line 353

def synchronize
	lock if !@locked
	begin
		yield(self)
	ensure
		unlock if @locked
	end
end

#unlockObject



368
369
370
371
372
# File 'lib/phusion_passenger/analytics_logger.rb', line 368

def unlock
	raise if !@locked
	@mutex.unlock
	@locked = false
end