From ba2d46829afada0ecc878df16b04078b13c6cfd9 Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 25 Feb 1998 06:52:43 +0000 Subject: reserved words & etc. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@91 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/cgi-lib.rb | 4 ++-- lib/thread.rb | 58 ++++++++++++++++++++++++++++++++++++++++------------------ 2 files changed, 42 insertions(+), 20 deletions(-) (limited to 'lib') diff --git a/lib/cgi-lib.rb b/lib/cgi-lib.rb index 7c46fb5955..02720b2835 100644 --- a/lib/cgi-lib.rb +++ b/lib/cgi-lib.rb @@ -45,7 +45,7 @@ class CGI end module_function :escape, :unescape - def initialize + def initialize(input = $stdin) # exception messages should be printed to stdout. STDERR.reopen(STDOUT) @@ -54,7 +54,7 @@ class CGI when "GET" ENV['QUERY_STRING'] or "" when "POST" - $stdin.read ENV['CONTENT_LENGTH'].to_i + input.read ENV['CONTENT_LENGTH'].to_i else read_from_cmdline end.split(/&/).each do |x| diff --git a/lib/thread.rb b/lib/thread.rb index c47d7b20a4..5262ec539d 100644 --- a/lib/thread.rb +++ b/lib/thread.rb @@ -20,7 +20,7 @@ end class Mutex def initialize @waiting = [] - @locked = FALSE; + @locked = false; end def locked? @@ -28,33 +28,33 @@ class Mutex end def try_lock - result = FALSE - Thread.critical = TRUE + result = false + Thread.critical = true unless @locked - @locked = TRUE - result = TRUE + @locked = true + result = true end - Thread.critical = FALSE + Thread.critical = false result end def lock - while (Thread.critical = TRUE; @locked) + while (Thread.critical = true; @locked) @waiting.push Thread.current Thread.stop end - @locked = TRUE - Thread.critical = FALSE + @locked = true + Thread.critical = false self end def unlock return unless @locked - Thread.critical = TRUE + Thread.critical = true wait = @waiting @waiting = [] - @locked = FALSE - Thread.critical = FALSE + @locked = false + Thread.critical = false for w in wait w.run end @@ -82,20 +82,20 @@ class Queue end def push(obj) - Thread.critical = TRUE + Thread.critical = true @que.push obj t = @waiting.shift - Thread.critical = FALSE + Thread.critical = false t.run if t end - def pop non_block=FALSE + def pop non_block=false item = nil until item - Thread.critical = TRUE + Thread.critical = true if @que.length == 0 if non_block - Thread.critical = FALSE + Thread.critical = false raise ThreadError, "queue empty" end @waiting.push Thread.current @@ -104,7 +104,7 @@ class Queue item = @que.shift end end - Thread.critical = FALSE + Thread.critical = false item end @@ -125,7 +125,28 @@ class SizedQueue= max + @max = max + else + Thread.critical = TRUE + diff = max - @max + @max = max + diff.times do + t = @queue_wait.shift + t.run if t + end + Thread.critical = FALSE + @max + end + end + def push(obj) + Thread.critical = true while @que.length >= @max @queue_wait.push Thread.current Thread.stop @@ -134,6 +155,7 @@ class SizedQueue