aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/rack_ext/lock.rb
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-01-17 10:16:31 -0600
committerJoshua Peek <josh@joshpeek.com>2009-01-17 10:16:31 -0600
commit515a1a332808eb7c2f9c006fc1903e1e8555b7fa (patch)
tree265b1e7477275c2a7958c65162e776054e806c84 /actionpack/lib/action_controller/rack_ext/lock.rb
parent3ee4e009185173aab78f6503ee45e3ef4482874e (diff)
downloadrails-515a1a332808eb7c2f9c006fc1903e1e8555b7fa.tar.gz
rails-515a1a332808eb7c2f9c006fc1903e1e8555b7fa.tar.bz2
rails-515a1a332808eb7c2f9c006fc1903e1e8555b7fa.zip
Lock middleware has been committed upstream
Diffstat (limited to 'actionpack/lib/action_controller/rack_ext/lock.rb')
-rw-r--r--actionpack/lib/action_controller/rack_ext/lock.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/rack_ext/lock.rb b/actionpack/lib/action_controller/rack_ext/lock.rb
new file mode 100644
index 0000000000..9bf1889065
--- /dev/null
+++ b/actionpack/lib/action_controller/rack_ext/lock.rb
@@ -0,0 +1,21 @@
+module Rack
+ # Rack::Lock was commited to Rack core
+ # http://github.com/rack/rack/commit/7409b0c
+ # Remove this when Rack 1.0 is released
+ unless defined? Lock
+ class Lock
+ FLAG = 'rack.multithread'.freeze
+
+ def initialize(app, lock = Mutex.new)
+ @app, @lock = app, lock
+ end
+
+ def call(env)
+ old, env[FLAG] = env[FLAG], false
+ @lock.synchronize { @app.call(env) }
+ ensure
+ env[FLAG] = old
+ end
+ end
+ end
+end