Module: FiberedMysql2::FiberedMonitorMixin
- Included in:
- FiberedDatabaseConnectionPool
- Defined in:
- lib/fibered_mysql2/fibered_database_connection_pool.rb
Overview
From Ruby’s MonitorMixin, with all occurrences of Thread changed to Fiber
Class Method Summary collapse
Instance Method Summary collapse
-
#mon_enter ⇒ Object
Enters exclusive section.
-
#mon_exit ⇒ Object
Leaves exclusive section.
-
#mon_synchronize ⇒ Object
(also: #synchronize)
Enters exclusive section and executes the block.
-
#mon_try_enter ⇒ Object
Attempts to enter exclusive section.
-
#new_cond ⇒ Object
Creates a new FiberedConditionVariable associated with the receiver.
Class Method Details
.extend_object(obj) ⇒ Object
24 25 26 27 |
# File 'lib/fibered_mysql2/fibered_database_connection_pool.rb', line 24 def self.extend_object(obj) super obj.__send__(:mon_initialize) end |
Instance Method Details
#mon_enter ⇒ Object
Enters exclusive section.
45 46 47 48 49 50 51 52 |
# File 'lib/fibered_mysql2/fibered_database_connection_pool.rb', line 45 def mon_enter if @mon_owner != Fiber.current @mon_mutex.lock @mon_owner = Fiber.current @mon_count = 0 end @mon_count += 1 end |
#mon_exit ⇒ Object
Leaves exclusive section.
57 58 59 60 61 62 63 64 |
# File 'lib/fibered_mysql2/fibered_database_connection_pool.rb', line 57 def mon_exit mon_check_owner @mon_count -= 1 if @mon_count == 0 @mon_owner = nil @mon_mutex.unlock end end |
#mon_synchronize ⇒ Object Also known as: synchronize
Enters exclusive section and executes the block. Leaves the exclusive section automatically when the block exits. See example under MonitorMixin
.
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/fibered_mysql2/fibered_database_connection_pool.rb', line 71 def mon_synchronize mon_enter begin yield ensure begin mon_exit rescue => ex ActiveRecord::Base.logger.error("Exception occurred while executing mon_exit: #{ex}") end end end |
#mon_try_enter ⇒ Object
Attempts to enter exclusive section. Returns false
if lock fails.
32 33 34 35 36 37 38 39 40 |
# File 'lib/fibered_mysql2/fibered_database_connection_pool.rb', line 32 def mon_try_enter if @mon_owner != Fiber.current @mon_mutex.try_lock or return false @mon_owner = Fiber.current @mon_count = 0 end @mon_count += 1 true end |
#new_cond ⇒ Object
Creates a new FiberedConditionVariable associated with the receiver.
89 90 91 |
# File 'lib/fibered_mysql2/fibered_database_connection_pool.rb', line 89 def new_cond FiberedConditionVariable.new(self) end |