2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
19 * Copyright (C) 2014 Cloudius Systems, Ltd.
22 #ifndef CEPH_MSG_DPDK_QUEUE_H_
23 #define CEPH_MSG_DPDK_QUEUE_H_
27 #include "circular_buffer.h"
31 std::queue<T, circular_buffer<T>> _q;
35 explicit queue(size_t size): _max(size) {}
39 // Returns false if the queue was full and the item was not pushed.
45 // Consumes items from the queue, passing them to @func, until @func
46 // returns false or the queue it empty
48 // Returns false if func returned false.
49 template <typename Func>
50 bool consume(Func&& func);
52 // Returns true when the queue is empty.
55 // Returns true when the queue is full.
58 size_t size() const { return _q.size(); }
60 // Destroy any items in the queue
69 inline bool queue<T>::push(T&& data) {
70 if (_q.size() < _max) {
71 _q.push(std::move(data));
80 inline T queue<T>::pop() {
81 T data = std::move(_q.front());
87 inline bool queue<T>::empty() const {
92 inline bool queue<T>::full() const {
93 return _q.size() == _max;
96 #endif /* CEPH_MSG_DPDK_QUEUE_H_ */