mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Including the mutex fix for folks by default.
git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@379 19e92222-5c0b-0410-8929-a290d50e31e9
This commit is contained in:
parent
88a2eb7c97
commit
a686152bf5
1 changed files with 34 additions and 0 deletions
34
lib/mutex_fix.rb
Normal file
34
lib/mutex_fix.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
require 'thread'
|
||||
|
||||
# monkey patch Mutex so it does not leak memory.
|
||||
class Mutex
|
||||
|
||||
def lock
|
||||
while (Thread.critical = true; @locked)
|
||||
@waiting.unshift Thread.current
|
||||
Thread.stop
|
||||
end
|
||||
@locked = true
|
||||
Thread.critical = false
|
||||
self
|
||||
end
|
||||
|
||||
def unlock
|
||||
return unless @locked
|
||||
Thread.critical = true
|
||||
@locked = false
|
||||
begin
|
||||
t = @waiting.pop
|
||||
t.wakeup if t
|
||||
rescue ThreadError
|
||||
retry
|
||||
end
|
||||
Thread.critical = false
|
||||
begin
|
||||
t.run if t
|
||||
rescue ThreadError
|
||||
end
|
||||
self
|
||||
end
|
||||
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue