diff --git a/common/utils/ds/spsc_q.c b/common/utils/ds/spsc_q.c index 6f05a19865..499af88d03 100644 --- a/common/utils/ds/spsc_q.c +++ b/common/utils/ds/spsc_q.c @@ -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) diff --git a/common/utils/ds/spsc_q.h b/common/utils/ds/spsc_q.h index 1149a80f7d..a18607de87 100644 --- a/common/utils/ds/spsc_q.h +++ b/common/utils/ds/spsc_q.h @@ -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); diff --git a/common/utils/ds/tests/test_spsc_q.cpp b/common/utils/ds/tests/test_spsc_q.cpp index 0c1638d490..35ccee7d22 100644 --- a/common/utils/ds/tests/test_spsc_q.cpp +++ b/common/utils/ds/tests/test_spsc_q.cpp @@ -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++; diff --git a/openair1/PHY/INIT/nr_init.c b/openair1/PHY/INIT/nr_init.c index 35b27468f6..5385eba113 100644 --- a/openair1/PHY/INIT/nr_init.c +++ b/openair1/PHY/INIT/nr_init.c @@ -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++) { diff --git a/openair1/PHY/NR_TRANSPORT/nr_prach.c b/openair1/PHY/NR_TRANSPORT/nr_prach.c index e8c66f00fe..24b08290de 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_prach.c +++ b/openair1/PHY/NR_TRANSPORT/nr_prach.c @@ -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)