From 210367ec889f5910e270d6ea2c7ddb8a8d939e61 Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 20 Jan 1999 04:59:39 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r372, which included commits to RCS files with non-trunk default branches. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@373 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/thread.rb | 163 ++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 131 insertions(+), 32 deletions(-) (limited to 'lib/thread.rb') diff --git a/lib/thread.rb b/lib/thread.rb index 4f294cc9a3..ec75144374 100644 --- a/lib/thread.rb +++ b/lib/thread.rb @@ -9,14 +9,20 @@ unless defined? Thread end unless defined? ThreadError - class ThreadError= max + @max = max + Thread.critical = FALSE + else + diff = max - @max + @max = max + Thread.critical = FALSE + diff.times do + t = @queue_wait.shift + t.run if t + end + end + max + end + + def push(obj) + Thread.critical = true + while @que.length >= @max + @queue_wait.push Thread.current + Thread.stop + Thread.critical = true + end + super + end + + def pop(*args) + Thread.critical = true + if @que.length < @max + t = @queue_wait.shift + t.run if t + end + super + end + + def num_waiting + @waiting.size + @queue_wait.size + end end -- cgit v1.2.3