Project

General

Profile

Backport #2092 ยป queue_ruby19.patch

quix (James M. Lawrence), 09/12/2009 09:49 PM

View differences:

lib/thread.rb (working copy)
144 144
  # Pushes +obj+ to the queue.
145 145
  #
146 146
  def push(obj)
147
    t = nil
148 147
    @mutex.synchronize{
149 148
      @que.push obj
150 149
      begin
......
154 153
        retry
155 154
      end
156 155
    }
157
    begin
158
      t.run if t
159
    rescue ThreadError
160
    end
161 156
  end
162 157

  
163 158
  #
......
176 171
  # thread isn't suspended, and an exception is raised.
177 172
  #
178 173
  def pop(non_block=false)
179
    while true
180
      @mutex.synchronize{
174
    @mutex.synchronize{
175
      while true
181 176
        if @que.empty?
182 177
          raise ThreadError, "queue empty" if non_block
183 178
          @waiting.push Thread.current
......
185 180
        else
186 181
          return @que.shift
187 182
        end
188
      }
189
    end
183
      end
184
    }
190 185
  end
191 186

  
192 187
  #
......
289 284
  # until space becomes available.
290 285
  #
291 286
  def push(obj)
292
    t = nil
293 287
    @mutex.synchronize{
294 288
      while true
295 289
        break if @que.length < @max
......
305 299
        retry
306 300
      end
307 301
    }
308

  
309
    begin
310
      t.run if t
311
    rescue ThreadError
312
    end
313 302
  end
314 303

  
315 304
  #
......
327 316
  #
328 317
  def pop(*args)
329 318
    retval = super
330
    t = nil
331 319
    @mutex.synchronize {
332 320
      if @que.length < @max
333 321
        begin
......
338 326
        end
339 327
      end
340 328
    }
341
    begin
342
      t.run if t
343
    rescue ThreadError
344
    end
345 329
    retval
346 330
  end
347 331