Make sure Semaphore uses get_lease inside of lock

In non-blocking mode it was possible for the semaphore to acquire
the lease without being inside a lock, so mor than max_leases couild
acquire the semaphore simultaneously. This fixes the issue by ensuring
that _get_lease is always called inside the lock.