Module: MonitorMixin
- Defined in:
- lib/monitor.rb
Defined Under Namespace
Classes: ConditionVariable
Class Method Summary collapse
Instance Method Summary collapse
-
#mon_enter ⇒ Object
Enters exclusive section.
-
#mon_exit ⇒ Object
Leaves exclusive section.
-
#mon_locked? ⇒ Boolean
Returns true if this monitor is locked by any thread.
-
#mon_owned? ⇒ Boolean
Returns true if this monitor is locked by current thread.
-
#mon_synchronize(&b) ⇒ Object
(also: #synchronize)
Enters exclusive section and executes the block.
-
#mon_try_enter ⇒ Object
(also: #try_mon_enter)
Attempts to enter exclusive section.
-
#new_cond ⇒ Object
Creates a new MonitorMixin::ConditionVariable associated with the Monitor object.
Class Method Details
.extend_object(obj) ⇒ Object
153 154 155 156 |
# File 'lib/monitor.rb', line 153 def self.extend_object(obj) super(obj) obj.__send__(:mon_initialize) end |
Instance Method Details
#mon_enter ⇒ Object
Enters exclusive section.
170 171 172 |
# File 'lib/monitor.rb', line 170 def mon_enter @mon_data.enter end |
#mon_exit ⇒ Object
Leaves exclusive section.
177 178 179 180 |
# File 'lib/monitor.rb', line 177 def mon_exit mon_check_owner @mon_data.exit end |
#mon_locked? ⇒ Boolean
Returns true if this monitor is locked by any thread
185 186 187 |
# File 'lib/monitor.rb', line 185 def mon_locked? @mon_data.mon_locked? end |
#mon_owned? ⇒ Boolean
Returns true if this monitor is locked by current thread.
192 193 194 |
# File 'lib/monitor.rb', line 192 def mon_owned? @mon_data.mon_owned? end |
#mon_synchronize(&b) ⇒ 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
.
201 202 203 |
# File 'lib/monitor.rb', line 201 def mon_synchronize(&b) @mon_data.synchronize(&b) end |
#mon_try_enter ⇒ Object Also known as: try_mon_enter
Attempts to enter exclusive section. Returns false
if lock fails.
161 162 163 |
# File 'lib/monitor.rb', line 161 def mon_try_enter @mon_data.try_enter end |
#new_cond ⇒ Object
Creates a new MonitorMixin::ConditionVariable associated with the Monitor object.
210 211 212 213 214 215 216 |
# File 'lib/monitor.rb', line 210 def new_cond unless defined?(@mon_data) mon_initialize @mon_initialized_by_new_cond = true end return ConditionVariable.new(@mon_data) end |