Class: WaitingPrioQueue
- Inherits:
-
Object
- Object
- WaitingPrioQueue
- Defined in:
- lib/appswarm/tools/waiting_prio_queue.rb
Instance Method Summary collapse
- #<<(value) ⇒ Object
-
#initialize(&block) ⇒ WaitingPrioQueue
constructor
A new instance of WaitingPrioQueue.
- #pop ⇒ Object
- #push(value) ⇒ Object
Constructor Details
#initialize(&block) ⇒ WaitingPrioQueue
Returns a new instance of WaitingPrioQueue.
2 3 4 5 6 7 8 9 10 |
# File 'lib/appswarm/tools/waiting_prio_queue.rb', line 2 def initialize(&block) @mutex=Mutex.new if block @block=block else @block=lambda {|a,b|a<=>b} end @buf=[] end |
Instance Method Details
#<<(value) ⇒ Object
20 21 22 |
# File 'lib/appswarm/tools/waiting_prio_queue.rb', line 20 def <<(value) push(value) end |
#pop ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/appswarm/tools/waiting_prio_queue.rb', line 24 def pop @waitThreads<<Thread.current loop do Thread.stop if empty? @mutex.synchronize { unless empty? value=getBest @waitThreads.delete(self) pp "POP",@waitThreads @waitThreads.uniq! return value end } end end |
#push(value) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/appswarm/tools/waiting_prio_queue.rb', line 12 def push(value) @mutex.synchronize { @buf<<value } @waitThreads.each{|th|th.wakeup} @waitThreads.uniq! pp "PUSH",@waitThreads end |