added release function for mac timers

master
Ismael Gomez 7 years ago
parent 9997f8c20a
commit 51fc9bffb1

@ -97,11 +97,13 @@ public:
bool running; bool running;
}; };
timers(uint32_t nof_timers_) : timer_list(nof_timers_) { timers(uint32_t nof_timers_) : timer_list(nof_timers_),used_timers(nof_timers_) {
nof_timers = nof_timers_; nof_timers = nof_timers_;
next_timer = 0; next_timer = 0;
nof_used_timers = 0;
for (uint32_t i=0;i<nof_timers;i++) { for (uint32_t i=0;i<nof_timers;i++) {
timer_list[i].id = i; timer_list[i].id = i;
used_timers[i] = false;
} }
} }
@ -133,17 +135,36 @@ public:
return NULL; return NULL;
} }
} }
void release_id(uint32_t i) {
if (nof_used_timers > 0 && i < nof_timers) {
used_timers[i] = false;
nof_used_timers--;
} else {
fprintf(stderr, "Error releasing timer: nof_used_timers=%d, nof_timers=%d\n", nof_used_timers, nof_timers);
}
}
uint32_t get_unique_id() { uint32_t get_unique_id() {
if (next_timer == nof_timers){ if (nof_used_timers >= nof_timers) {
printf("No more unique timer ids (Only %d timers available)\n", nof_timers); fprintf(stderr, "Error getting uinque timer id: no more timers available\n");
return 0;
} else {
while(used_timers[next_timer]) {
next_timer++;
if (next_timer >= nof_timers) {
next_timer=0; next_timer=0;
} }
return next_timer++; }
used_timers[next_timer] = true;
nof_used_timers++;
return next_timer;
}
} }
private: private:
uint32_t nof_timers;
uint32_t next_timer; uint32_t next_timer;
uint32_t nof_used_timers;
uint32_t nof_timers;
std::vector<timer> timer_list; std::vector<timer> timer_list;
std::vector<bool> used_timers;
}; };
} // namespace srslte } // namespace srslte

@ -79,7 +79,14 @@ void rrc::init(phy_interface_rrc *phy_,
nas = nas_; nas = nas_;
usim = usim_; usim = usim_;
rrc_log = rrc_log_; rrc_log = rrc_log_;
// Use MAC timers
mac_timers = mac_timers_; mac_timers = mac_timers_;
t301 = mac_timers->get_unique_id();
t310 = mac_timers->get_unique_id();
t311 = mac_timers->get_unique_id();
safe_reset_timer = mac_timers->get_unique_id();
pthread_mutex_init(&mutex, NULL); pthread_mutex_init(&mutex, NULL);
@ -1492,10 +1499,6 @@ void rrc::set_mac_default()
void rrc::set_rrc_default() { void rrc::set_rrc_default() {
N310 = 1; N310 = 1;
N311 = 1; N311 = 1;
t301 = mac_timers->get_unique_id();
t310 = mac_timers->get_unique_id();
t311 = mac_timers->get_unique_id();
safe_reset_timer = mac_timers->get_unique_id();
mac_timers->get(t310)->set(this, 1000); mac_timers->get(t310)->set(this, 1000);
mac_timers->get(t311)->set(this, 1000); mac_timers->get(t311)->set(this, 1000);
mac_timers->get(safe_reset_timer)->set(this, 10); mac_timers->get(safe_reset_timer)->set(this, 10);

Loading…
Cancel
Save