5G-MAG Reference Tools - MBMS Modem
MultichannelRingbuffer.h
Go to the documentation of this file.
1 // 5G-MAG Reference Tools
2 // MBMS Modem Process
3 //
4 // Copyright (C) 2021 Klaus Kühnhammer (Österreichische Rundfunksender GmbH & Co KG)
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU Affero General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Affero General Public License for more details.
15 //
16 // You should have received a copy of the GNU Affero General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 //
19 
20 #pragma once
21 #include <stddef.h>
22 #include <vector>
23 #include <mutex>
24 
25 #include "srsran/srsran.h"
26 #include "srsran/phy/common/phy_common.h"
27 
29  public:
30  explicit MultichannelRingbuffer(size_t size, size_t channels);
31  virtual ~MultichannelRingbuffer();
32 
33  inline size_t free_size() { std::lock_guard<std::mutex> lock(_mutex); return _size - _used; }
34  inline size_t used_size() { std::lock_guard<std::mutex> lock(_mutex); return _used; }
35  inline size_t capacity() { std::lock_guard<std::mutex> lock(_mutex);return _size; }
36 
37  inline void clear() {std::lock_guard<std::mutex> lock(_mutex); _head = _used = 0; };
38 
39  std::vector<void*> read_head();
40  std::vector<void*> write_head(size_t* writeable);
41  void commit(size_t written);
42 
43  void read(std::vector<char*> dest, size_t bytes);
44 
45  private:
46  std::vector<char*> _buffers;
47  size_t _size;
48  size_t _channels;
49  size_t _head;
50  size_t _used;
51  std::mutex _mutex;
52 };
void read(std::vector< char * > dest, size_t bytes)
std::vector< void * > read_head()
std::vector< char * > _buffers
std::vector< void * > write_head(size_t *writeable)
MultichannelRingbuffer(size_t size, size_t channels)