rubygems/rubygems — pull request #951 by tenderlove (2014-06-21 22:07:47+00:00)
Title: cut monitor entry / exits in half on "happy path" requires

Before this change RUBYGEMS_ACTIVATION_MONITOR would enter and exit
twice for every call to require. This commit pushes the "exit" call
outside of the `ensure` block to the `rescue` and unlocks in the
appropriate place. Eliminating the effectively "global" unlock in then
`ensure` block allows us to lock and unlock once during happy path
requires, and only lock / unlock twice when `gem_original_require` fails
and we need to attempt to activate the gem.

Here is a test to demonstrate the problem:

```ruby
require 'rubygems'
require 'tempfile'

moncalls = []
trace = TracePoint.new(:c_call, :call) do |tp|
if tp.method_id == :mon_enter
moncalls << [tp.defined_class, tp.method_id, tp.path]
end
end

f = Tempfile.open(['foo', '.rb'])
f.write "true"
f.close

$: << File.dirname(f.path)
file = File.basename f.path, '.rb'

trace.enable
require file
trace.disable

p moncalls.length
```

Before this change `moncalls.length` will return 2, after this commit,
it returns 1.