| 266 | public: |
| 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 { |
no test coverage detected