~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to lib/thread.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#
2
 
#               thread.rb - thread support classes
3
 
#                       by Yukihiro Matsumoto <matz@netlab.co.jp>
 
2
#               thread.rb - thread support classes
 
3
#                       by Yukihiro Matsumoto <matz@netlab.co.jp>
4
4
#
5
5
# Copyright (C) 2001  Yukihiro Matsumoto
6
6
# Copyright (C) 2000  Network Applied Communication Laboratory, Inc.
69
69
        @waiters.push(Thread.current)
70
70
      end
71
71
      mutex.sleep timeout
 
72
    ensure
 
73
      @waiters_mutex.synchronize do
 
74
        @waiters.delete(Thread.current)
 
75
      end
72
76
    end
73
77
    self
74
78
  end
90
94
  # Wakes up all threads waiting for this lock.
91
95
  #
92
96
  def broadcast
93
 
    # TODO: imcomplete
 
97
    # TODO: incomplete
94
98
    waiters0 = nil
95
99
    @waiters_mutex.synchronize do
96
100
      waiters0 = @waiters.dup
140
144
  def initialize
141
145
    @que = []
142
146
    @waiting = []
143
 
    @que.taint          # enable tainted comunication
 
147
    @que.taint          # enable tainted communication
144
148
    @waiting.taint
145
149
    self.taint
146
150
    @mutex = Mutex.new
248
252
    raise ArgumentError, "queue size must be positive" unless max > 0
249
253
    @max = max
250
254
    @queue_wait = []
251
 
    @queue_wait.taint           # enable tainted comunication
 
255
    @queue_wait.taint           # enable tainted comunication
252
256
    super()
253
257
  end
254
258
 
274
278
    }
275
279
    if diff
276
280
      diff.times do
277
 
        begin
278
 
          t = @queue_wait.shift
279
 
          t.run if t
280
 
        rescue ThreadError
281
 
          retry
282
 
        end
 
281
        begin
 
282
          t = @queue_wait.shift
 
283
          t.run if t
 
284
        rescue ThreadError
 
285
          retry
 
286
        end
283
287
      end
284
288
    end
285
289
    max