From ea171c75c0b941dc982e1e932a4c5a267705e038 Mon Sep 17 00:00:00 2001
From: Robert Schmidt <robert.schmidt@openairinterface.org>
Date: Fri, 31 May 2024 12:25:51 +0200
Subject: [PATCH] nr_timer: consistently pass by ref, rename to
 nr_timer_is_active()

Pass consistently the NR_timer_t object through a pointer. Since we have
to modify all occurrences of is_nr_timer_active(), we use that occasion
and rename that function to nr_timer_is_active() to make it consistent
with all other functions, starting with nr_timer.
---
 common/utils/nr/nr_common.c                   | 16 ++++++++--------
 common/utils/nr/nr_common.h                   |  6 +++---
 common/utils/nr/tests/test_nr_common.cpp      |  8 ++++----
 openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c  |  4 ++--
 openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c  |  2 +-
 openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c   |  4 ++--
 openair2/RRC/NR_UE/rrc_UE.c                   |  8 ++++----
 openair2/RRC/NR_UE/rrc_timers_and_constants.c | 14 +++++++-------
 8 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/common/utils/nr/nr_common.c b/common/utils/nr/nr_common.c
index c1ed6c7546a..f851c26eee6 100644
--- a/common/utils/nr/nr_common.c
+++ b/common/utils/nr/nr_common.c
@@ -1161,9 +1161,9 @@ void nr_timer_stop(NR_timer_t *timer)
   timer->counter = 0;
 }
 
-bool is_nr_timer_active(NR_timer_t timer)
+bool nr_timer_is_active(const NR_timer_t *timer)
 {
-  return timer.active;
+  return timer->active;
 }
 
 bool nr_timer_tick(NR_timer_t *timer)
@@ -1173,23 +1173,23 @@ bool nr_timer_tick(NR_timer_t *timer)
     timer->counter += timer->step;
     if (timer->target == UINT_MAX) // infinite target, never expires
       return false;
-    expired = nr_timer_expired(*timer);
+    expired = nr_timer_expired(timer);
     if (expired)
       timer->active = false;
   }
   return expired;
 }
 
-bool nr_timer_expired(NR_timer_t timer)
+bool nr_timer_expired(const NR_timer_t *timer)
 {
-  if (timer.target == UINT_MAX) // infinite target, never expires
+  if (timer->target == UINT_MAX) // infinite target, never expires
     return false;
-  return (timer.counter >= timer.target);
+  return timer->counter >= timer->target;
 }
 
-uint32_t nr_timer_elapsed_time(NR_timer_t timer)
+uint32_t nr_timer_elapsed_time(const NR_timer_t *timer)
 {
-  return timer.counter;
+  return timer->counter;
 }
 
 void nr_timer_setup(NR_timer_t *timer, const uint32_t target, const uint32_t step)
diff --git a/common/utils/nr/nr_common.h b/common/utils/nr/nr_common.h
index fcefa294618..0f294921815 100644
--- a/common/utils/nr/nr_common.h
+++ b/common/utils/nr/nr_common.h
@@ -163,19 +163,19 @@ void nr_timer_setup(NR_timer_t *timer, const uint32_t target, const uint32_t ste
  * @param timer Timer to be checked
  * @return Indication if the timer is expired or not
  */
-bool nr_timer_expired(NR_timer_t timer);
+bool nr_timer_expired(const NR_timer_t *timer);
 /**
  * @brief To check if a timer is active
  * @param timer Timer to be checked
  * @return Indication if the timer is active or not
  */
-bool is_nr_timer_active(NR_timer_t timer);
+bool nr_timer_is_active(const NR_timer_t *timer);
 /**
  * @brief To return how much time has passed since start of timer
  * @param timer Timer to be checked
  * @return Time passed since start of timer
  */
-uint32_t nr_timer_elapsed_time(NR_timer_t timer);
+uint32_t nr_timer_elapsed_time(const NR_timer_t *timer);
 
 
 extern const nr_bandentry_t nr_bandtable[];
diff --git a/common/utils/nr/tests/test_nr_common.cpp b/common/utils/nr/tests/test_nr_common.cpp
index fede91b8ee4..c780736a51b 100644
--- a/common/utils/nr/tests/test_nr_common.cpp
+++ b/common/utils/nr/tests/test_nr_common.cpp
@@ -29,13 +29,13 @@ TEST(nr_common, nr_timer) {
   NR_timer_t timer;
   nr_timer_setup(&timer, 10, 1);
   nr_timer_start(&timer);
-  EXPECT_TRUE(is_nr_timer_active(timer));
-  EXPECT_FALSE(nr_timer_expired(timer));
+  EXPECT_TRUE(nr_timer_is_active(&timer));
+  EXPECT_FALSE(nr_timer_expired(&timer));
   for (auto i = 0; i < 10; i++) {
     nr_timer_tick(&timer);
   }
-  EXPECT_FALSE(is_nr_timer_active(timer));
-  EXPECT_TRUE(nr_timer_expired(timer));
+  EXPECT_FALSE(nr_timer_is_active(&timer));
+  EXPECT_TRUE(nr_timer_expired(&timer));
 }
 
 
diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c
index c26e8a56297..c52a67c5a26 100644
--- a/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c
+++ b/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c
@@ -790,7 +790,7 @@ void nr_ue_get_rach(NR_UE_MAC_INST_t *mac, int CC_id, frame_t frame, uint8_t gNB
     }
   }
 
-  if (is_nr_timer_active(ra->contention_resolution_timer)) {
+  if (nr_timer_is_active(&ra->contention_resolution_timer)) {
     nr_ue_contention_resolution(mac, CC_id, frame, nr_slot_tx, prach_resources);
   }
 }
@@ -851,7 +851,7 @@ void nr_ue_contention_resolution(NR_UE_MAC_INST_t *mac, int cc_id, frame_t frame
 {
   RA_config_t *ra = &mac->ra;
 
-  if (nr_timer_expired(ra->contention_resolution_timer)) {
+  if (nr_timer_expired(&ra->contention_resolution_timer)) {
     ra->t_crnti = 0;
     nr_timer_stop(&ra->contention_resolution_timer);
     // Signal PHY to quit RA procedure
diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c
index ac743c0f60e..ccfa8615875 100644
--- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c
+++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c
@@ -2543,7 +2543,7 @@ int8_t nr_ue_get_SR(NR_UE_MAC_INST_t *mac, frame_t frame, slot_t slot, NR_Schedu
         sr_id); // todo
 
   // TODO check if the PUCCH resource for the SR transmission occasion does not overlap with a UL-SCH resource
-  if (!sr_info->pending || is_nr_timer_active(sr_info->prohibitTimer))
+  if (!sr_info->pending || nr_timer_is_active(&sr_info->prohibitTimer))
     return 0;
 
   if (sr_info->counter < sr_info->maxTransmissions) {
diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c
index 557a393ce27..b66ff3203c7 100644
--- a/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c
+++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c
@@ -1297,7 +1297,7 @@ static void nr_update_sr(NR_UE_MAC_INST_t *mac)
 
   // if a Regular BSR has been triggered and logicalChannelSR-DelayTimer is not running
   if (((sched_info->BSR_reporting_active & NR_BSR_TRIGGER_REGULAR) == 0)
-      || is_nr_timer_active(sched_info->sr_DelayTimer))
+      || nr_timer_is_active(&sched_info->sr_DelayTimer))
     return;
 
   nr_lcordered_info_t *lc_info = get_lc_info_from_lcid(mac, sched_info->regularBSR_trigger_lcid);
@@ -1527,7 +1527,7 @@ void nr_ue_ul_scheduler(NR_UE_MAC_INST_t *mac, nr_uplink_indication_t *ul_info)
       NR_LC_SCHEDULING_INFO *sched_info = get_scheduling_info_from_lcid(mac, lcid);
       int32_t bj = sched_info->Bj;
       if (lc_info->pbr < UINT_MAX) {
-        uint32_t slots_elapsed = nr_timer_elapsed_time(sched_info->Bj_timer); // slots elapsed since Bj was last incremented
+        uint32_t slots_elapsed = nr_timer_elapsed_time(&sched_info->Bj_timer); // slots elapsed since Bj was last incremented
         // it is safe to divide by 1k since pbr in lc_info is computed multiplying by 1000 the RRC value to convert kB/s to B/s
         uint32_t pbr_ms = lc_info->pbr / 1000;
         bj += ((pbr_ms * slots_elapsed) >> mac->current_UL_BWP->scs); // each slot length is 1/scs ms
diff --git a/openair2/RRC/NR_UE/rrc_UE.c b/openair2/RRC/NR_UE/rrc_UE.c
index eb5113cceec..fc3693ea7b6 100644
--- a/openair2/RRC/NR_UE/rrc_UE.c
+++ b/openair2/RRC/NR_UE/rrc_UE.c
@@ -479,7 +479,7 @@ static void nr_rrc_ue_decode_NR_BCCH_BCH_Message(NR_UE_RRC_INST_t *rrc,
   
   // Actions following cell selection while T311 is running
   NR_UE_Timers_Constants_t *timers = &rrc->timers_and_constants;
-  if (is_nr_timer_active(timers->T311)) {
+  if (nr_timer_is_active(&timers->T311)) {
     nr_timer_stop(&timers->T311);
     rrc->ra_trigger = RRC_CONNECTION_REESTABLISHMENT;
 
@@ -1695,7 +1695,7 @@ static int nr_rrc_ue_decode_dcch(NR_UE_RRC_INST_t *rrc,
 void nr_rrc_handle_ra_indication(NR_UE_RRC_INST_t *rrc, bool ra_succeeded)
 {
   NR_UE_Timers_Constants_t *timers = &rrc->timers_and_constants;
-  if (ra_succeeded && is_nr_timer_active(timers->T304)) {
+  if (ra_succeeded && nr_timer_is_active(&timers->T304)) {
     // successful Random Access procedure triggered by reconfigurationWithSync
     nr_timer_stop(&timers->T304);
     // TODO handle the rest of procedures as described in 5.3.5.3 for when
@@ -2218,14 +2218,14 @@ void nr_rrc_going_to_IDLE(NR_UE_RRC_INST_t *rrc,
     }
   }
   if (!waitTime) {
-    if (is_nr_timer_active(tac->T302)) {
+    if (nr_timer_is_active(&tac->T302)) {
       nr_timer_stop(&tac->T302);
       // TODO barring alleviation as in 5.3.14.4
       // not implemented
       LOG_E(NR_RRC,"Go to IDLE. Barring alleviation not implemented\n");
     }
   }
-  if (is_nr_timer_active(tac->T390)) {
+  if (nr_timer_is_active(&tac->T390)) {
     nr_timer_stop(&tac->T390);
     // TODO barring alleviation as in 5.3.14.4
     // not implemented
diff --git a/openair2/RRC/NR_UE/rrc_timers_and_constants.c b/openair2/RRC/NR_UE/rrc_timers_and_constants.c
index 70a467691b2..9e734a3188e 100644
--- a/openair2/RRC/NR_UE/rrc_timers_and_constants.c
+++ b/openair2/RRC/NR_UE/rrc_timers_and_constants.c
@@ -560,7 +560,7 @@ void handle_rlf_sync(NR_UE_Timers_Constants_t *tac,
 {
   if (sync_msg == IN_SYNC) {
     tac->N310_cnt = 0;
-    if (is_nr_timer_active(tac->T310)) {
+    if (nr_timer_is_active(&tac->T310)) {
       tac->N311_cnt++;
       // Upon receiving N311 consecutive "in-sync" indications
       if (tac->N311_cnt >= tac->N311_k) {
@@ -573,12 +573,12 @@ void handle_rlf_sync(NR_UE_Timers_Constants_t *tac,
   else {
     // OUT_OF_SYNC
     tac->N311_cnt = 0;
-    if(is_nr_timer_active(tac->T300) ||
-       is_nr_timer_active(tac->T301) ||
-       is_nr_timer_active(tac->T304) ||
-       is_nr_timer_active(tac->T310) ||
-       is_nr_timer_active(tac->T311) ||
-       is_nr_timer_active(tac->T319))
+    if(nr_timer_is_active(&tac->T300) ||
+       nr_timer_is_active(&tac->T301) ||
+       nr_timer_is_active(&tac->T304) ||
+       nr_timer_is_active(&tac->T310) ||
+       nr_timer_is_active(&tac->T311) ||
+       nr_timer_is_active(&tac->T319))
       return;
     tac->N310_cnt++;
     // upon receiving N310 consecutive "out-of-sync" indications
-- 
GitLab