Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

More queue fiddling

  • Loading branch information...
commit 02c6410f019d1fcfdce343ba901ea80e9e45c89f 1 parent c981c2e
Seth Morabito authored
Showing with 7 additions and 2 deletions.
  1. +7 −2 server/lib/bdrb_thread_pool.rb
View
9 server/lib/bdrb_thread_pool.rb
@@ -21,8 +21,9 @@ def initialize(master,size,logger)
@logger = logger
@size = size
@threads = []
- @work_queue = Queue.new
+ @work_queue = []
@mutex = Monitor.new
+ @cv = @mutex.new_cond
@size.times { add_thread }
end
@@ -50,7 +51,9 @@ def defer(method_name,args = nil)
@mutex.synchronize do
job_key = Thread.current[:job_key]
persistent_job_id = Thread.current[:persistent_job_id]
- @work_queue << WorkData.new(args,job_key,method_name,persistent_job_id)
+ @cv.wait_while { @work_queue.size >= size }
+ @work_queue.push(WorkData.new(args,job_key,method_name,persistent_job_id))
+ @cv.broadcast
end
end
@@ -63,7 +66,9 @@ def add_thread
begin
task = nil
@mutex.synchronize do
+ @cv.wait_while { @work_queue.size == 0 }
task = @work_queue.pop
+ @cv.broadcast
end
if task
Thread.current[:job_key] = task.job_key
Please sign in to comment.
Something went wrong with that request. Please try again.