From b814252d728cb08f159da1777feca4f8e9362327 Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 9 Feb 1998 10:56:24 +0000 Subject: 1.1b7 pre git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@67 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/tempfile.rb | 23 +++++++++++++++-------- lib/thread.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/tempfile.rb b/lib/tempfile.rb index 78b770c5a4..9d986e7691 100644 --- a/lib/tempfile.rb +++ b/lib/tempfile.rb @@ -15,6 +15,19 @@ require 'final' class Tempfile < SimpleDelegator Max_try = 10 + def Tempfile.callback(path) + lambda{ + print "removing ", path, "..." + if File.exist?(path) + File.unlink(path) + end + if File.exist?(path + '.lock') + File.unlink(path + '.lock') + end + print "done\n" + } + end + def initialize(basename, tmpdir = '/tmp') umask = File.umask(0177) begin @@ -33,14 +46,7 @@ class Tempfile < SimpleDelegator n += 1 end - @clean_files = proc {|id| - if File.exist?(@tmpname) - File.unlink(@tmpname) - end - if File.exist?(@tmpname + '.lock') - File.unlink(@tmpname + '.lock') - end - } + @clean_files = Tempfile.callback(@tmpname) ObjectSpace.define_finalizer(self, @clean_files) @tmpfile = File.open(@tmpname, 'w+') @@ -75,6 +81,7 @@ if __FILE__ == $0 f = Tempfile.new("foo") f.print("foo\n") f.close + f = nil f.open p f.gets # => "foo\n" f.close(true) diff --git a/lib/thread.rb b/lib/thread.rb index 4f294cc9a3..8f7f6cdd6a 100644 --- a/lib/thread.rb +++ b/lib/thread.rb @@ -13,6 +13,10 @@ unless defined? ThreadError end end +if $DEBUG + Thread.abort_on_exception = true +end + class Mutex def initialize @waiting = [] @@ -107,4 +111,30 @@ class Queue def length @que.length end + alias size length +end + +class SizedQueue= @max + @queue_wait.push Thread.current + Thread.stop + end + super + end + + def pop(*args) + if @que.length < @max + t = @queue_wait.shift + t.run if t + end + pop = super + pop + end end -- cgit v1.2.3