diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-02-25 06:52:43 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-02-25 06:52:43 +0000 |
commit | ba2d46829afada0ecc878df16b04078b13c6cfd9 (patch) | |
tree | a7403d95e2a7f658160e623eec8568c1969b5165 /lib | |
parent | 6bab1e5abd81d57fe1046a7acc7f699ab6ee3190 (diff) |
reserved words & etc.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@91 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/cgi-lib.rb | 4 | ||||
-rw-r--r-- | lib/thread.rb | 58 |
2 files changed, 42 insertions, 20 deletions
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<Queue super() end + def max + @max + end + + def max=(max) + if @max >= 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<Queue end def pop(*args) + Thread.critical = true if @que.length < @max t = @queue_wait.shift t.run if t |