Module: MonitorMixin
- Included in:
- Empathy::EM::Monitor, Monitor
- Defined in:
- lib/monitor.rb
Overview
See MRI Ruby's MonitorMixin This file is derived from MRI Ruby 1.9.3 monitor.rb
Copyright (C) 2001 Shugo Maeda [email protected]
The only changes are constant lookups, it dynamically uses thread constants from the included class/extended object
Note this relaces monitor.rb defined by ruby - so even if you don't include empathy you may end up using this module.
Defined Under Namespace
Classes: ConditionVariable
Instance Method Summary collapse
-
#mon_enter ⇒ void
Enters exclusive section.
-
#mon_exit ⇒ void
Leaves exclusive section.
-
#mon_synchronize ⇒ void
(also: #synchronize)
Enters exclusive section and executes the block.
-
#mon_try_enter ⇒ Boolean
(also: #try_mon_enter)
Attempts to enter exclusive section.
-
#new_cond ⇒ ConditionVariable
A new condition variable associated with the receiver.
Instance Method Details
#mon_enter ⇒ void
This method returns an undefined value.
Enters exclusive section.
102 103 104 105 106 107 108 |
# File 'lib/monitor.rb', line 102 def mon_enter if @mon_owner != mon_class_lookup(:Thread).current @mon_mutex.lock @mon_owner = mon_class_lookup(:Thread).current end @mon_count += 1 end |
#mon_exit ⇒ void
This method returns an undefined value.
Leaves exclusive section.
114 115 116 117 118 119 120 121 |
# File 'lib/monitor.rb', line 114 def mon_exit mon_check_owner @mon_count -=1 if @mon_count == 0 @mon_owner = nil @mon_mutex.unlock end end |
#mon_synchronize ⇒ void Also known as: synchronize
This method returns an undefined value.
Enters exclusive section and executes the block. Leaves the exclusive section automatically when the block exits.
127 128 129 130 131 132 133 134 |
# File 'lib/monitor.rb', line 127 def mon_synchronize mon_enter begin yield ensure mon_exit end end |
#mon_try_enter ⇒ Boolean Also known as: try_mon_enter
Attempts to enter exclusive section.
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/monitor.rb', line 85 def mon_try_enter if @mon_owner != mon_class_lookup(:Thread).current unless @mon_mutex.try_lock return false end @mon_owner = mon_class_lookup(:Thread).current end @mon_count += 1 return true end |
#new_cond ⇒ ConditionVariable
Returns a new condition variable associated with the receiver.
140 141 142 |
# File 'lib/monitor.rb', line 140 def new_cond return ConditionVariable.new(self) end |