| 919 | // Never allocates. Thread-safe. |
| 920 | template<typename U> |
| 921 | bool try_dequeue(U& item) |
| 922 | { |
| 923 | // Instead of simply trying each producer in turn (which could cause needless contention on the first |
| 924 | // producer), we score them heuristically. |
| 925 | size_t nonEmptyCount = 0; |
| 926 | ProducerBase* best = nullptr; |
| 927 | size_t bestSize = 0; |
| 928 | for (auto ptr = producerListTail.load(std::memory_order_acquire); nonEmptyCount < 3 && ptr != nullptr; ptr = ptr->next_prod()) { |
| 929 | auto size = ptr->size_approx(); |
| 930 | if (size > 0) { |
| 931 | if (size > bestSize) { |
| 932 | bestSize = size; |
| 933 | best = ptr; |
| 934 | } |
| 935 | ++nonEmptyCount; |
| 936 | } |
| 937 | } |
| 938 | |
| 939 | // If there was at least one non-empty queue but it appears empty at the time |
| 940 | // we try to dequeue from it, we need to make sure every queue's been tried |
| 941 | if (nonEmptyCount > 0) { |
| 942 | if ((details::likely)(best->dequeue(item))) { |
| 943 | return true; |
| 944 | } |
| 945 | for (auto ptr = producerListTail.load(std::memory_order_acquire); ptr != nullptr; ptr = ptr->next_prod()) { |
| 946 | if (ptr != best && ptr->dequeue(item)) { |
| 947 | return true; |
| 948 | } |
| 949 | } |
| 950 | } |
| 951 | return false; |
| 952 | } |
| 953 | |
| 954 | // Attempts to dequeue from the queue. |
| 955 | // Returns false if all producer streams appeared empty at the time they |
nothing calls this directly
no test coverage detected