mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	* lib/monitor.rb (wait): fix timeout support.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_6@1302 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									c5b9600397
								
							
						
					
					
						commit
						baba657821
					
				
					 2 changed files with 16 additions and 10 deletions
				
			
		| 
						 | 
				
			
			@ -1,7 +1,9 @@
 | 
			
		|||
Mon Apr  2 13:54:21 2001  Shugo Maeda <shugo@ruby-lang.org>
 | 
			
		||||
Mon Apr  2 14:25:49 2001  Shugo Maeda <shugo@ruby-lang.org>
 | 
			
		||||
 | 
			
		||||
	* lib/monitor.rb (wait): ensure reentrance.
 | 
			
		||||
 | 
			
		||||
	* lib/monitor.rb (wait): fix timeout support.
 | 
			
		||||
 | 
			
		||||
Mon Apr  2 12:44:53 2001  Shugo Maeda <shugo@ruby-lang.org>
 | 
			
		||||
 | 
			
		||||
	* lib/net/imap.rb: backport from ruby-1.7.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -69,6 +69,15 @@ module MonitorMixin
 | 
			
		|||
	raise ThreadError, "current thread not owner"
 | 
			
		||||
      end
 | 
			
		||||
      
 | 
			
		||||
      if timeout
 | 
			
		||||
	ct = Thread.current
 | 
			
		||||
	timeout_thread = Thread.start {
 | 
			
		||||
	  Thread.pass
 | 
			
		||||
	  sleep(timeout)
 | 
			
		||||
	  ct.raise(Timeout.new)
 | 
			
		||||
	}
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      Thread.critical = true
 | 
			
		||||
      count = @monitor.mon_count
 | 
			
		||||
      @monitor.mon_count = 0
 | 
			
		||||
| 
						 | 
				
			
			@ -80,23 +89,18 @@ module MonitorMixin
 | 
			
		|||
      end
 | 
			
		||||
      t.wakeup if t
 | 
			
		||||
      @waiters.push(Thread.current)
 | 
			
		||||
      
 | 
			
		||||
      if timeout
 | 
			
		||||
	t = Thread.current
 | 
			
		||||
	timeout_thread = Thread.start {
 | 
			
		||||
	  sleep(timeout)
 | 
			
		||||
	  t.raise(Timeout.new)
 | 
			
		||||
	}
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      begin
 | 
			
		||||
	Thread.stop
 | 
			
		||||
      rescue Timeout
 | 
			
		||||
	@waiters.delete(Thread.current)
 | 
			
		||||
      ensure
 | 
			
		||||
	Thread.critical = true
 | 
			
		||||
	if timeout && timeout_thread.alive?
 | 
			
		||||
	  Thread.kill(timeout_thread)
 | 
			
		||||
	end
 | 
			
		||||
	if @waiters.include?(Thread.current)  # interrupted?
 | 
			
		||||
	  @waiters.delete(Thread.current)
 | 
			
		||||
	end
 | 
			
		||||
	while @monitor.mon_owner &&
 | 
			
		||||
	    @monitor.mon_owner != Thread.current
 | 
			
		||||
	  @monitor.mon_waiting_queue.push(Thread.current)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue