Class: MonitorVariable
- Inherits:
-
Object
- Object
- MonitorVariable
- Defined in:
- lib/buzzcore/extra/thread_utils.rb
Instance Method Summary collapse
- #clear ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(aMonitor) ⇒ MonitorVariable
constructor
A new instance of MonitorVariable.
- #reject_value ⇒ Object
- #value ⇒ Object
- #value=(aValue) ⇒ Object
Constructor Details
#initialize(aMonitor) ⇒ MonitorVariable
Returns a new instance of MonitorVariable.
259 260 261 262 263 264 |
# File 'lib/buzzcore/extra/thread_utils.rb', line 259 def initialize(aMonitor) @monitor = aMonitor @cvRead = @monitor.new_cond @cvWrite = @monitor.new_cond @empty = true end |
Instance Method Details
#clear ⇒ Object
299 300 301 302 303 304 305 |
# File 'lib/buzzcore/extra/thread_utils.rb', line 299 def clear @monitor.synchronize do @value = nil @empty = true @cvWrite.signal end end |
#empty? ⇒ Boolean
295 296 297 |
# File 'lib/buzzcore/extra/thread_utils.rb', line 295 def empty? @empty end |
#reject_value ⇒ Object
307 308 309 310 311 312 313 314 315 |
# File 'lib/buzzcore/extra/thread_utils.rb', line 307 def reject_value @monitor.synchronize do if !empty? clear else @reject_next = true end end end |
#value ⇒ Object
266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/buzzcore/extra/thread_utils.rb', line 266 def value @monitor.synchronize do while empty? @cvRead.wait(@timeout) end result = @value @value = nil @empty = true @cvWrite.signal result end end |
#value=(aValue) ⇒ Object
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/buzzcore/extra/thread_utils.rb', line 279 def value=(aValue) @monitor.synchronize do until empty? @cvWrite.wait(@timeout) end if @reject_next clear else @value = aValue @empty = false @cvRead.signal end aValue end end |