Class: PhusionPassenger::AnalyticsLogger::Lock
- Defined in:
- lib/phusion_passenger/analytics_logger.rb
Instance Method Summary collapse
-
#initialize(mutex) ⇒ Lock
constructor
A new instance of Lock.
- #lock ⇒ Object
- #reset(mutex, lock_now = true) ⇒ Object
- #synchronize ⇒ Object
- #unlock ⇒ Object
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
#lock ⇒ Object
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 |
#synchronize ⇒ Object
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 |
#unlock ⇒ Object
368 369 370 371 372 |
# File 'lib/phusion_passenger/analytics_logger.rb', line 368 def unlock raise if !@locked @mutex.unlock @locked = false end |