| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d0ba007 commit af2908a
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,4 @@ | |||
| 1 | - #pragma once | ||
| 1 | + #pragma once | ||
| 2 | 2 | ||
| 3 | 3 | #include <bit> | |
| 4 | 4 | ||
@@ -293,28 +293,6 @@ class UnboundedWSQ { | |||
| 293 | 293 | template <typename I> | |
| 294 | 294 | void bulk_push(I& first, size_t N); | |
| 295 | 295 | ||
| 296 | - /** | ||
| 297 | - @brief pops out an item from the queue | ||
| 298 | - | ||
| 299 | - This method pops an item from the queue. | ||
| 300 | - If the queue is empty, empty_value() is returned. | ||
| 301 | - The elements popped out from the queue follow a last-in-first-out (LIFO) order. | ||
| 302 | - | ||
| 303 | - @code{.cpp} | ||
| 304 | - tf::UnboundedWSQ<int> wsq(10); | ||
| 305 | - wsq.push(1); | ||
| 306 | - wsq.push(2); | ||
| 307 | - wsq.push(3); | ||
| 308 | - assert(wsq.pop().value() = 3); | ||
| 309 | - assert(wsq.pop().value() = 2); | ||
| 310 | - assert(wsq.pop().value() = 1); | ||
| 311 | - assert(wsq.pop() == std::nullopt); | ||
| 312 | - @endcode | ||
| 313 | - | ||
| 314 | - Only the owner thread can pop out an item from the queue. | ||
| 315 | - */ | ||
| 316 | - value_type pop(); | ||
| 317 | - | ||
| 318 | 296 | /** | |
| 319 | 297 | @brief steals an item from the queue | |
| 320 | 298 | ||
@@ -440,46 +418,12 @@ void UnboundedWSQ<T>::bulk_push(I& first, size_t N) { | |||
| 440 | 418 | _bottom.store(b, std::memory_order_release); | |
| 441 | 419 | } | |
| 442 | 420 | ||
| 443 | - // Function: pop | ||
| 444 | - template <typename T> | ||
| 445 | - typename UnboundedWSQ<T>::value_type | ||
| 446 | - UnboundedWSQ<T>::pop() { | ||
| 447 | - | ||
| 448 | - int64_t b = _bottom.load(std::memory_order_relaxed) - 1; | ||
| 449 | - Array* a = _array.load(std::memory_order_relaxed); | ||
| 450 | - _bottom.store(b, std::memory_order_relaxed); | ||
| 451 | - std::atomic_thread_fence(std::memory_order_seq_cst); | ||
| 452 | - int64_t t = _top.load(std::memory_order_relaxed); | ||
| 453 | - | ||
| 454 | - //T item {nullptr}; | ||
| 455 | - auto item = empty_value(); | ||
| 456 | - | ||
| 457 | - if(t <= b) { | ||
| 458 | - item = a->pop(b); | ||
| 459 | - if(t == b) { | ||
| 460 | - // the last item just got stolen | ||
| 461 | - if(!_top.compare_exchange_strong(t, t+1, std::memory_order_seq_cst, | ||
| 462 | - std::memory_order_relaxed)) { | ||
| 463 | - //item = nullptr; | ||
| 464 | - item = empty_value(); | ||
| 465 | - } | ||
| 466 | - _bottom.store(b + 1, std::memory_order_relaxed); | ||
| 467 | - } | ||
| 468 | - } | ||
| 469 | - else { | ||
| 470 | - _bottom.store(b + 1, std::memory_order_relaxed); | ||
| 471 | - } | ||
| 472 | - | ||
| 473 | - return item; | ||
| 474 | - } | ||
| 475 | - | ||
| 476 | 421 | // Function: steal | |
| 477 | 422 | template <typename T> | |
| 478 | 423 | typename UnboundedWSQ<T>::value_type | |
| 479 | 424 | UnboundedWSQ<T>::steal() { | |
| 480 | 425 | ||
| 481 | - int64_t t = _top.load(std::memory_order_acquire); | ||
| 482 | - std::atomic_thread_fence(std::memory_order_seq_cst); | ||
| 426 | + int64_t t = _top.load(std::memory_order_relaxed); | ||
| 483 | 427 | int64_t b = _bottom.load(std::memory_order_acquire); | |
| 484 | 428 | ||
| 485 | 429 | //T item {nullptr}; | |
@@ -489,7 +433,7 @@ UnboundedWSQ<T>::steal() { | |||
| 489 | 433 | Array* a = _array.load(std::memory_order_consume); | |
| 490 | 434 | item = a->pop(t); | |
| 491 | 435 | if(!_top.compare_exchange_strong(t, t+1, | |
| 492 | - std::memory_order_seq_cst, | ||
| 436 | + std::memory_order_acq_rel, | ||
| 493 | 437 | std::memory_order_relaxed)) { | |
| 494 | 438 | //return nullptr; | |
| 495 | 439 | return empty_value(); | |
@@ -833,8 +777,8 @@ BoundedWSQ<T, LogSize>::pop() { | |||
| 833 | 777 | item = _buffer[b & BufferMask].load(std::memory_order_relaxed); | |
| 834 | 778 | if(t == b) { | |
| 835 | 779 | // the last item just got stolen | |
| 836 | - if(!_top.compare_exchange_strong(t, t+1, | ||
| 837 | - std::memory_order_seq_cst, | ||
| 780 | + if(!_top.compare_exchange_strong(t, t+1, | ||
| 781 | + std::memory_order_acq_rel, | ||
| 838 | 782 | std::memory_order_relaxed)) { | |
| 839 | 783 | //item = nullptr; | |
| 840 | 784 | item = empty_value(); | |
@@ -853,7 +797,7 @@ BoundedWSQ<T, LogSize>::pop() { | |||
| 853 | 797 | template <typename T, size_t LogSize> | |
| 854 | 798 | typename BoundedWSQ<T, LogSize>::value_type | |
| 855 | 799 | BoundedWSQ<T, LogSize>::steal() { | |
| 856 | - int64_t t = _top.load(std::memory_order_acquire); | ||
| 800 | + int64_t t = _top.load(std::memory_order_relaxed); | ||
| 857 | 801 | std::atomic_thread_fence(std::memory_order_seq_cst); | |
| 858 | 802 | int64_t b = _bottom.load(std::memory_order_acquire); | |
| 859 | 803 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments