Skip to content

Commit

Permalink
Return processing lock to dispatcher, the finer grained lock was inco…
Browse files Browse the repository at this point in the history
…mpatible with the reloading in development mode.

This commit also adds ActionController::Dispatcher#dispatch_unlocking -- non-locking version of dispatch.
It's named anologously to POSIX {getc,getchar,...}_unlocked functions.

Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#1170 state:committed]
  • Loading branch information
Aliaksey Kandratsenka authored and NZKoz committed Oct 4, 2008
1 parent f550c86 commit b437a7d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
9 changes: 1 addition & 8 deletions actionpack/lib/action_controller/base.rb
Expand Up @@ -290,8 +290,6 @@ class Base
@@allow_concurrency = false
cattr_accessor :allow_concurrency

@@guard = Monitor.new

# Modern REST web services often need to submit complex data to the web application.
# The <tt>@@param_parsers</tt> hash lets you register handlers which will process the HTTP body and add parameters to the
# <tt>params</tt> hash. These handlers are invoked for POST and PUT requests.
Expand Down Expand Up @@ -532,12 +530,7 @@ def process(request, response, method = :perform_action, *arguments) #:nodoc:
assign_names

log_processing

if @@allow_concurrency
send(method, *arguments)
else
@@guard.synchronize { send(method, *arguments) }
end
send(method, *arguments)

send_response
ensure
Expand Down
14 changes: 13 additions & 1 deletion actionpack/lib/action_controller/dispatcher.rb
Expand Up @@ -2,6 +2,8 @@ module ActionController
# Dispatches requests to the appropriate controller and takes care of
# reloading the app after each request when Dependencies.load? is true.
class Dispatcher
@@guard = Mutex.new

class << self
def define_dispatcher_callbacks(cache_classes)
unless cache_classes
Expand Down Expand Up @@ -99,7 +101,7 @@ def initialize(output = $stdout, request = nil, response = nil)
@output, @request, @response = output, request, response
end

def dispatch
def dispatch_unlocked
begin
run_callbacks :before_dispatch
handle_request
Expand All @@ -110,6 +112,16 @@ def dispatch
end
end

def dispatch
if ActionController::Base.allow_concurrency
dispatch_unlocked
else
@@guard.synchronize do
dispatch_unlocked
end
end
end

def dispatch_cgi(cgi, session_options)
if cgi ||= self.class.failsafe_response(@output, '400 Bad Request') { CGI.new }
@request = CgiRequest.new(cgi, session_options)
Expand Down

0 comments on commit b437a7d

Please sign in to comment.