MCPcopy Create free account
hub / github.com/bshoshany/thread-pool / try_acquire

Method try_acquire

tests/BS_thread_pool_test.cpp:184–193  ·  view source on GitHub ↗

* @brief Tries to atomically decrement the internal counter by 1 if it is greater than 0; no blocking occurs regardless. * * @return `true` if decremented the internal counter, `false` otherwise. */

Source from the content-addressed store, hash-verified

182 * @return `true` if decremented the internal counter, `false` otherwise.
183 */
184 bool try_acquire()
185 {
186 std::scoped_lock lock(mutex);
187 if (counter > 0)
188 {
189 --counter;
190 return true;
191 }
192 return false;
193 }
194
195 /**
196 * @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 `rel_time` duration has been exceeded.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected