Permalink
Browse files

Ensure rack.multithread is set back to original value. Accept externa…

…l lock.
  • Loading branch information...
1 parent 788ab84 commit 86abd6887dac9ee233740399f9e5758309af512e @jeremy jeremy committed Dec 18, 2008
Showing with 8 additions and 10 deletions.
  1. +8 −10 actionpack/lib/action_controller/lock.rb
@@ -1,18 +1,16 @@
module ActionController
class Lock
- def initialize(app)
- @app = app
- @lock = Mutex.new
+ FLAG = 'rack.multithread'.freeze
+
+ def initialize(app, lock = Mutex.new)
+ @app, @lock = app, lock
end
def call(env)
- old_multithread = env["rack.multithread"]
- env["rack.multithread"] = false
- response = @lock.synchronize do
- @app.call(env)
- end
- env["rack.multithread"] = old_multithread
- response
+ old, env[FLAG] = env[FLAG], false
+ @lock.synchronize { @app.call(env) }
+ ensure
+ env[FLAG] = old
end
end
end

0 comments on commit 86abd68

Please sign in to comment.