The previous code attempted to lock instance_count and instance with a
CriticalSection, but the CriticalSection was not static, so each
function invocation got its own instance. Locking this call-specific
instance doesn't actually stop any other threads from concurrently
accessing the same function-scope globals, so this function had a data
race, which broke tsan tests (and possibly other things).
Making the CriticalSection shared among function calls will actually
synchronize access to the globals and allow our tsan tests to pass.
BUG=webrtc:3062
Review-Url: https://codereview.webrtc.org/2890213002
Cr-Commit-Position: refs/heads/master@{#18296}