Merge pull request #6407 from pinetops/565c1b0a0772ac6cf91c77e9285806f7b028614c

Template concurrency fixes
Conflicts:

	actionpack/lib/action_view/template.rb
Fix generators to help with ambiguous `ApplicationController` issue

In development mode, dependencies are loaded dynamically at runtime,
using `const_missing`. Because of that, when one of the constants is
already loaded and `const_missing` is not triggered, user can end up
with unexpected results.

Given such file in an Engine:

```ruby
module Blog
  class PostsController < ApplicationController
  end
end
```

If you load it first, before loading any application files, it will
correctly load `Blog::ApplicationController`, because second line will
hit `const_missing`. However if you load `ApplicationController` first,
the constant will be loaded already, `const_missing` hook will not be
fired and in result `PostsController` will inherit from
`ApplicationController` instead of `Blog::ApplicationController`.

Since it can't be fixed in `AS::Dependencies`, the easiest fix is to
just explicitly load application controller.

closes #6413
Make connection pool fair with respect to waiting threads.
More info on commit messages in contributing guide

Add more info on how to write a good commit messages along with
example showing nicely formatted commit message.

Rails git history does not look too well when you try to figure out why
particular changes were introduced. We can do much better than that and
it's never too late to start.
add CollectionProxy#destroy documentation
Refactoring: turn unless/else into if/else
Merge pull request #6424 from avakarev/refactoring_unless-else

Refactoring: just turn unless/else into if/else
Merge pull request #6143 from senny/composed_of_converter_returns_nil

allow the :converter Proc form composed_of to return nil
improve CollectionProxy#destroy documentation
add CollectionProxy#reload documentation
fix CollectionProxy documentation markup
Merge pull request #6416 from pmahoney/threadsafe-connection-pool

Make connection pool fair with respect to waiting threads.
Merge pull request #2549 from trek/RoutingErrorForMissingControllers

When a route references a missing controller, raise ActionController::RoutingError with clearer message
Make the Resolver template cache threadsafe  - closes #6404

The Template cache in the Resolver can be accessed by multiple threads
similtaneously in multi-threaded environments. The cache is implemented
using a Hash, which isn't threadsafe in all VMs (notably JRuby).

This commit extracts the cache to a new Cache class and adds mutexes to
prevent concurrent access.
More granular locking of the Resolver template cache

In order to avoid holding a global lock when doing template
resolution, instead add individual locks on a per cache entry
basis. The global lock is now only used for manipulation of the main
cache data structure.
Merge pull request #6425 from pinetops/resolver_concurrency_fix

Resolver concurrency fix
Prevent concurrent compilation of templates - closes #6400

This addresses an issue where in multi-threaded environments
multiple threads can attempt to compile a template at the same time,
which occasionally causes particular templates to end up in a bad
state.

So, add synchronization such that only a single thread can attempt to
compile a template at one time.
Revert "Merge pull request #6425 from pinetops/resolver_concurrency_fix"

This reverts commit 254c04286c5916ae7f91eb6e173b312e7a74e364, reversing
changes made to 513a0525c24c2944630acfa465b22cd2f4601adf.
Make the Resolver template cache threadsafe  - closes #6404

The Template cache in the Resolver can be accessed by multiple threads
similtaneously in multi-threaded environments. The cache is implemented
using a Hash, which isn't threadsafe in all VMs (notably JRuby).

This commit extracts the cache to a new Cache class and adds mutexes to
prevent concurrent access.
More granular locking of the Resolver template cache

In order to avoid holding a global lock when doing template
resolution, instead add individual locks on a per cache entry
basis. The global lock is now only used for manipulation of the main
cache data structure.