Fix incorrect test of the condition variable state, spotted by Richard Oudkerk. This could cause the internal condition variable to grow without bounds.
Extract cross-platform condition variable support into a separate file and provide user-mode non-recursive locks for Windows.