/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include <atomic> #include <vector> #include <folly/Memory.h> #include <folly/concurrency/UnboundedQueue.h> #include <folly/lang/Align.h> namespace folly { /// PriorityUnboundedQueueSet /// /// A set of per-priority queues, and an interface for accessing them. /// /// Functions: /// Consumer operations: /// bool try_dequeue(T&); /// Optional<T> try_dequeue(); /// Tries to extract an element from the front of the least-priority /// backing queue which has an element, if any. /// T const* try_peek(); /// Returns a pointer to the element at the front of the least-priority /// backing queue which has an element, if any. Only allowed when /// SingleConsumer is true. /// Note: /// Queues at lower priority are tried before queues at higher priority. /// /// Secondary functions: /// queue& at_priority(size_t); /// queue const& at_priority(size_t) const; /// Returns a reference to the owned queue at the given priority. /// size_t size() const; /// Returns an estimate of the total size of the owned queues. /// bool empty() const; /// Returns true only if all of the owned queues were empty during the /// call. /// Note: size() and empty() are guaranteed to be accurate only if the /// owned queues are not changed concurrently. template < typename T, bool SingleProducer, bool SingleConsumer, bool MayBlock, size_t LgSegmentSize = 8, size_t LgAlign = constexpr_log2(hardware_destructive_interference_size), template <typename> class Atom = std::atomic> class PriorityUnboundedQueueSet { … }; // PriorityUnboundedQueueSet /* Aliases */ PriorityUSPSCQueueSet; PriorityUMPSCQueueSet; PriorityUSPMCQueueSet; PriorityUMPMCQueueSet; } // namespace folly