mirror of
https://gitlab.eurecom.fr/oai/openairinterface5g.git
synced 2026-07-13 04:30:28 +00:00
spsc_q: make compile on older compilers
While compiling the spsc_q unit tests on some compilers, some
complain with
/openairinterface5g/common/utils/ds/tests/test_spsc_q.cpp:11:44: error: use of deleted function ‘spsc_q::spsc_q(spsc_q&&)’
spsc_q_t rb = spsc_q_alloc(2, sizeof(int));
/openairinterface5g/common/utils/ds/spsc_q.h:19:16: error: use of deleted function ‘std::atomic<long unsigned int>::atomic(const std::atomic<long unsigned int>&)’
These compiles cannot copy the atomic. Change the API to avoid this
copy.
"Older" compiler here means g++-11/12.
Signed-off-by: Robert Schmidt <robert.schmidt@openairinterface.org>
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
|
||||
#include "spsc_q.h"
|
||||
|
||||
spsc_q_t spsc_q_alloc(size_t cnt, size_t elsiz)
|
||||
bool spsc_q_alloc(spsc_q_t *rbn, size_t cnt, size_t elsiz)
|
||||
{
|
||||
/* internally, use one element more: the ringbuffer is full if
|
||||
* (write_idx + 1) % cnt == read_idx, so it's full if one element is still
|
||||
@@ -17,7 +17,8 @@ spsc_q_t spsc_q_alloc(size_t cnt, size_t elsiz)
|
||||
cnt += 1;
|
||||
spsc_q_t rb = {.cnt = cnt, .elsiz = elsiz};
|
||||
rb.buf = calloc(cnt, elsiz);
|
||||
return rb;
|
||||
*rbn = rb;
|
||||
return rb.buf != NULL;
|
||||
}
|
||||
|
||||
void spsc_q_free(spsc_q_t *rb)
|
||||
|
||||
@@ -25,7 +25,7 @@ typedef struct spsc_q {
|
||||
atomic_size_t read_idx;
|
||||
} spsc_q_t;
|
||||
|
||||
spsc_q_t spsc_q_alloc(size_t cnt, size_t elsiz);
|
||||
bool spsc_q_alloc(spsc_q_t *rbn, size_t cnt, size_t elsiz);
|
||||
void spsc_q_free(spsc_q_t *rb);
|
||||
|
||||
bool spsc_q_put(spsc_q_t *rb, const void *src, size_t elsiz);
|
||||
|
||||
@@ -8,7 +8,8 @@ extern "C" {
|
||||
}
|
||||
|
||||
TEST(spsc_q, basic_test) {
|
||||
spsc_q_t rb = spsc_q_alloc(2, sizeof(int));
|
||||
spsc_q_t rb;
|
||||
EXPECT_TRUE(spsc_q_alloc(&rb, 2, sizeof(int)));
|
||||
|
||||
int a = 1;
|
||||
EXPECT_TRUE(spsc_q_put(&rb, &a, sizeof(a)));
|
||||
@@ -26,7 +27,8 @@ TEST(spsc_q, basic_test) {
|
||||
}
|
||||
|
||||
TEST(spsc_q, cont_write) {
|
||||
spsc_q_t rb = spsc_q_alloc(10, sizeof(int));
|
||||
spsc_q_t rb;
|
||||
EXPECT_TRUE(spsc_q_alloc(&rb, 10, sizeof(int)));
|
||||
|
||||
int a = 1;
|
||||
for (int i = 0; i < 1111; ++i) {
|
||||
@@ -57,7 +59,8 @@ bool count(const void *data, void *user)
|
||||
return true; /* count all */
|
||||
}
|
||||
TEST(spsc_q, iterator) {
|
||||
spsc_q_t rb = spsc_q_alloc(10, sizeof(int));
|
||||
spsc_q_t rb;
|
||||
EXPECT_TRUE(spsc_q_alloc(&rb, 10, sizeof(int)));
|
||||
int n = 8;
|
||||
for (int i = 0; i < n; ++i)
|
||||
EXPECT_TRUE(spsc_q_put(&rb, &i, sizeof(i)));
|
||||
@@ -85,7 +88,8 @@ bool drop(const void *data, void *user)
|
||||
return true; /* drop all */
|
||||
}
|
||||
TEST(spsc_q, drop) {
|
||||
spsc_q_t rb = spsc_q_alloc(10, sizeof(int));
|
||||
spsc_q_t rb;
|
||||
EXPECT_TRUE(spsc_q_alloc(&rb, 10, sizeof(int)));
|
||||
int n = 8;
|
||||
for (int i = 0; i < n; ++i)
|
||||
EXPECT_TRUE(spsc_q_put(&rb, &i, sizeof(i)));
|
||||
@@ -104,7 +108,8 @@ TEST(spsc_q, drop) {
|
||||
|
||||
TEST(spsc_q, full) {
|
||||
int n = 3;
|
||||
spsc_q_t rb = spsc_q_alloc(n, sizeof(int));
|
||||
spsc_q_t rb;
|
||||
EXPECT_TRUE(spsc_q_alloc(&rb, n, sizeof(int)));
|
||||
int a = 1;
|
||||
EXPECT_TRUE(spsc_q_put(&rb, &a, sizeof(a)));
|
||||
a++;
|
||||
|
||||
@@ -424,11 +424,15 @@ void init_nr_transport(PHY_VARS_gNB *gNB)
|
||||
gNB->max_nb_pusch = buffer_ul_slots ? MAX_MOBILES_PER_GNB * buffer_ul_slots : 1;
|
||||
|
||||
int max_nb_pucch = buffer_ul_slots ? MAX_MOBILES_PER_GNB * buffer_ul_slots : 1;
|
||||
gNB->pucch_queue = spsc_q_alloc(max_nb_pucch, sizeof(NR_gNB_PUCCH_job_t));
|
||||
gNB->pusch_queue = spsc_q_alloc(gNB->max_nb_pusch, sizeof(NR_gNB_PUSCH_job_t));
|
||||
bool ret;
|
||||
ret = spsc_q_alloc(&gNB->pucch_queue, max_nb_pucch, sizeof(NR_gNB_PUCCH_job_t));
|
||||
DevAssert(ret);
|
||||
ret = spsc_q_alloc(&gNB->pusch_queue, gNB->max_nb_pusch, sizeof(NR_gNB_PUSCH_job_t));
|
||||
DevAssert(ret);
|
||||
|
||||
int max_nb_srs = buffer_ul_slots ? buffer_ul_slots << 1 : 1; // assuming at most 2 SRS per slot
|
||||
gNB->srs_queue = spsc_q_alloc(max_nb_srs, sizeof(NR_gNB_SRS_job_t));
|
||||
ret = spsc_q_alloc(&gNB->srs_queue, max_nb_srs, sizeof(NR_gNB_SRS_job_t));
|
||||
DevAssert(ret);
|
||||
|
||||
gNB->ulsch = (NR_gNB_ULSCH_t *)malloc16(gNB->max_nb_pusch * sizeof(NR_gNB_ULSCH_t));
|
||||
for (int i = 0; i < gNB->max_nb_pusch; i++) {
|
||||
|
||||
@@ -15,8 +15,11 @@
|
||||
void init_nr_prach(PHY_VARS_gNB *gNB)
|
||||
{
|
||||
int num_prach = 16;
|
||||
gNB->prach_ru_queue = spsc_q_alloc(num_prach, sizeof(prach_item_t));
|
||||
gNB->prach_l1rx_queue = spsc_q_alloc(num_prach, sizeof(prach_item_t));
|
||||
bool ret;
|
||||
ret = spsc_q_alloc(&gNB->prach_ru_queue, num_prach, sizeof(prach_item_t));
|
||||
DevAssert(ret);
|
||||
ret = spsc_q_alloc(&gNB->prach_l1rx_queue, num_prach, sizeof(prach_item_t));
|
||||
DevAssert(ret);
|
||||
}
|
||||
|
||||
void reset_nr_prach(PHY_VARS_gNB *gNB)
|
||||
|
||||
Reference in New Issue
Block a user