This might be useful to avoid blocking threads in the thread pool just for
waiting on a global lock. It might also be useful to allow stopping build
actions while they're waiting for a lock.
* Aquire the mutex before setting `m_exclusivelyOwned = false`; otherwise
it might be set after `lock()` has checked it but before `lock()` has
entered `wait()` leading to a deadlock
* Check state again after `wait()` because it may also be unblocked
"spuriously" so it isn't guaranteed that the state will have actually
changed after unblocking
* Can not use a normal mutex because we don't want to tie the resources to
a specific thread (and instead e.g. to a build action which might not be
executed by a single thread)
* A semaphore would do that but libstdc++ only supports it as of GCC 11 and
besides it wouldn't distinguish between shared and exclusive locking