mirror of https://github.com/pvnis/srsRAN_4G.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.7 KiB
C
95 lines
2.7 KiB
C
6 years ago
|
/*
|
||
5 years ago
|
* Copyright 2013-2020 Software Radio Systems Limited
|
||
7 years ago
|
*
|
||
6 years ago
|
* This file is part of srsLTE.
|
||
7 years ago
|
*
|
||
6 years ago
|
* srsLTE is free software: you can redistribute it and/or modify
|
||
7 years ago
|
* it under the terms of the GNU Affero General Public License as
|
||
|
* published by the Free Software Foundation, either version 3 of
|
||
|
* the License, or (at your option) any later version.
|
||
|
*
|
||
6 years ago
|
* srsLTE is distributed in the hope that it will be useful,
|
||
7 years ago
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU Affero General Public License for more details.
|
||
|
*
|
||
|
* A copy of the GNU Affero General Public License can be found in
|
||
|
* the LICENSE file in the top-level directory of this distribution
|
||
|
* and at http://www.gnu.org/licenses/.
|
||
|
*
|
||
|
*/
|
||
|
|
||
4 years ago
|
/*
|
||
|
* @file byte_buffer_queue.h
|
||
|
*
|
||
|
* @brief Queue of unique pointers to byte buffers used in PDCP and RLC TX queues.
|
||
|
* Uses a blocking queue with bounded capacity to block higher layers
|
||
|
* when pushing uplink traffic
|
||
|
*/
|
||
7 years ago
|
|
||
4 years ago
|
#ifndef SRSLTE_BYTE_BUFFERQUEUE_H
|
||
|
#define SRSLTE_BYTE_BUFFERQUEUE_H
|
||
7 years ago
|
|
||
|
#include "srslte/common/block_queue.h"
|
||
|
#include "srslte/common/common.h"
|
||
|
#include <pthread.h>
|
||
|
|
||
|
namespace srslte {
|
||
|
|
||
4 years ago
|
class byte_buffer_queue : public block_queue<unique_byte_buffer_t>::call_mutexed_itf
|
||
7 years ago
|
{
|
||
|
public:
|
||
4 years ago
|
byte_buffer_queue(int capacity = 128) : queue(capacity) { queue.set_mutexed_itf(this); }
|
||
7 years ago
|
// increase/decrease unread_bytes inside push/pop mutexed operations
|
||
6 years ago
|
void pushing(const unique_byte_buffer_t& msg) final { unread_bytes += msg->N_bytes; }
|
||
|
void popping(const unique_byte_buffer_t& msg) final
|
||
6 years ago
|
{
|
||
7 years ago
|
if (unread_bytes > msg->N_bytes) {
|
||
|
unread_bytes -= msg->N_bytes;
|
||
|
} else {
|
||
|
unread_bytes = 0;
|
||
|
}
|
||
7 years ago
|
}
|
||
6 years ago
|
void write(unique_byte_buffer_t msg) { queue.push(std::move(msg)); }
|
||
7 years ago
|
|
||
5 years ago
|
srslte::error_type<unique_byte_buffer_t> try_write(unique_byte_buffer_t&& msg)
|
||
5 years ago
|
{
|
||
|
return queue.try_push(std::move(msg));
|
||
|
}
|
||
6 years ago
|
|
||
6 years ago
|
unique_byte_buffer_t read() { return queue.wait_pop(); }
|
||
7 years ago
|
|
||
6 years ago
|
bool try_read(unique_byte_buffer_t* msg) { return queue.try_pop(msg); }
|
||
7 years ago
|
|
||
5 years ago
|
void resize(uint32_t capacity) { queue.resize(capacity); }
|
||
|
uint32_t size() { return (uint32_t)queue.size(); }
|
||
7 years ago
|
|
||
5 years ago
|
uint32_t size_bytes() { return unread_bytes; }
|
||
7 years ago
|
|
||
|
uint32_t size_tail_bytes()
|
||
|
{
|
||
|
if (!queue.empty()) {
|
||
6 years ago
|
const unique_byte_buffer_t& m = queue.front();
|
||
6 years ago
|
if (m.get()) {
|
||
7 years ago
|
return m->N_bytes;
|
||
|
}
|
||
|
}
|
||
5 years ago
|
return 0;
|
||
7 years ago
|
}
|
||
|
|
||
|
// This is a hack to reset N_bytes counter when queue is corrupted (see line 89)
|
||
5 years ago
|
void reset() { unread_bytes = 0; }
|
||
7 years ago
|
|
||
5 years ago
|
bool is_empty() { return queue.empty(); }
|
||
6 years ago
|
|
||
4 years ago
|
bool is_full() { return queue.full(); }
|
||
|
|
||
7 years ago
|
private:
|
||
6 years ago
|
block_queue<unique_byte_buffer_t> queue;
|
||
4 years ago
|
uint32_t unread_bytes = 0;
|
||
7 years ago
|
};
|
||
|
|
||
|
} // namespace srslte
|
||
|
|
||
4 years ago
|
#endif // SRSLTE_BYTE_BUFFERQUEUE_H
|