| 21 | : _parent(kTopTrackedLock), _mutex(&mutex), _owns(false) { |
| 22 | kTopTrackedLock = this; |
| 23 | |
| 24 | // Poll rather than block: std::recursive_mutex has no timed acquire, and swapping the type |
| 25 | // would tax every RecursiveMutex user. 1ms granularity is negligible against the input |
| 26 | // deadlines this serves. |
| 27 | while (!(_owns = mutex.try_lock())) { |
| 28 | if (std::chrono::steady_clock::now() >= deadline) { |
| 29 | break; |
| 30 | } |
| 31 | std::this_thread::sleep_for(std::chrono::milliseconds(1)); |
| 32 | } |
| 33 | } |