Backport #2092 » queue_ruby19.patch
lib/thread.rb (working copy) | ||
---|---|---|
# Pushes +obj+ to the queue.
|
||
#
|
||
def push(obj)
|
||
t = nil
|
||
@mutex.synchronize{
|
||
@que.push obj
|
||
begin
|
||
... | ... | |
retry
|
||
end
|
||
}
|
||
begin
|
||
t.run if t
|
||
rescue ThreadError
|
||
end
|
||
end
|
||
#
|
||
... | ... | |
# thread isn't suspended, and an exception is raised.
|
||
#
|
||
def pop(non_block=false)
|
||
while true
|
||
@mutex.synchronize{
|
||
@mutex.synchronize{
|
||
while true
|
||
if @que.empty?
|
||
raise ThreadError, "queue empty" if non_block
|
||
@waiting.push Thread.current
|
||
... | ... | |
else
|
||
return @que.shift
|
||
end
|
||
}
|
||
end
|
||
end
|
||
}
|
||
end
|
||
#
|
||
... | ... | |
# until space becomes available.
|
||
#
|
||
def push(obj)
|
||
t = nil
|
||
@mutex.synchronize{
|
||
while true
|
||
break if @que.length < @max
|
||
... | ... | |
retry
|
||
end
|
||
}
|
||
begin
|
||
t.run if t
|
||
rescue ThreadError
|
||
end
|
||
end
|
||
#
|
||
... | ... | |
#
|
||
def pop(*args)
|
||
retval = super
|
||
t = nil
|
||
@mutex.synchronize {
|
||
if @que.length < @max
|
||
begin
|
||
... | ... | |
end
|
||
end
|
||
}
|
||
begin
|
||
t.run if t
|
||
rescue ThreadError
|
||
end
|
||
retval
|
||
end
|
||