Reduce critical section so as not to block unnecessarily.
Reduce critical section even more. Use lock only to update counters.
Small re-factorization.
Another round at re-factoring this.
Prevent situation in which an attempt to obtain a connection would fail without even waiting for queue.
Merge pull request #189 from edevil/master

Reduce critical section protected by global lock