| 202 | */ |
| 203 | template <class Rep, class Period> |
| 204 | bool try_acquire_for(const std::chrono::duration<Rep, Period>& rel_time) |
| 205 | { |
| 206 | std::unique_lock lock(mutex); |
| 207 | if (!cv.wait_for(lock, rel_time, |
| 208 | [this] |
| 209 | { |
| 210 | return counter > 0; |
| 211 | })) |
| 212 | return false; |
| 213 | --counter; |
| 214 | return true; |
| 215 | } |
| 216 | |
| 217 | /** |
| 218 | * @brief Tries to atomically decrement the internal counter by 1 if it is greater than 0; otherwise blocks until it is greater than 0 and can successfully decrement the internal counter, or the `abs_time` time point has been passed. |