MCPcopy Create free account
hub / github.com/GDRETools/gdsdecomp / try_push

Method try_push

external/atomic_queue/atomic_queue.h:268–284  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

266public:
267 template<class T>
268 bool try_push(T&& element) noexcept {
269 auto head = head_.load(X);
270 if(Derived::spsc_) {
271 if(static_cast<int>(head - tail_.load(X)) >= static_cast<int>(static_cast<Derived&>(*this).size_))
272 return false;
273 head_.store(head + 1, X);
274 }
275 else {
276 do {
277 if(static_cast<int>(head - tail_.load(X)) >= static_cast<int>(static_cast<Derived&>(*this).size_))
278 return false;
279 } while(ATOMIC_QUEUE_UNLIKELY(!head_.compare_exchange_weak(head, head + 1, X, X))); // This loop is not FIFO.
280 }
281
282 static_cast<Derived&>(*this).do_push(std::forward<T>(element), head);
283 return true;
284 }
285
286 template<class T>
287 bool try_pop(T& element) noexcept {

Callers 5

add_download_taskMethod · 0.45
logvMethod · 0.45
end_taskMethod · 0.45
pushMethod · 0.45

Calls 2

loadMethod · 0.45
do_pushMethod · 0.45

Tested by

no test coverage detected