added release function for mac timers

This commit is contained in:
Ismael Gomez 2017-08-29 12:01:30 +02:00
parent 9997f8c20a
commit 51fc9bffb1
2 changed files with 37 additions and 13 deletions

View File

@ -97,11 +97,13 @@ public:
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_;
next_timer = 0;
nof_used_timers = 0;
for (uint32_t i=0;i<nof_timers;i++) {
timer_list[i].id = i;
used_timers[i] = false;
}
}
@ -133,17 +135,36 @@ public:
return NULL;
}
}
uint32_t get_unique_id() {
if (next_timer == nof_timers){
printf("No more unique timer ids (Only %d timers available)\n", nof_timers);
next_timer = 0;
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() {
if (nof_used_timers >= 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;
}
}
used_timers[next_timer] = true;
nof_used_timers++;
return next_timer;
}
return next_timer++;
}
private:
uint32_t nof_timers;
uint32_t next_timer;
uint32_t nof_used_timers;
uint32_t nof_timers;
std::vector<timer> timer_list;
std::vector<bool> used_timers;
};
} // namespace srslte

View File

@ -79,7 +79,14 @@ void rrc::init(phy_interface_rrc *phy_,
nas = nas_;
usim = usim_;
rrc_log = rrc_log_;
// Use 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);
@ -1492,10 +1499,6 @@ void rrc::set_mac_default()
void rrc::set_rrc_default() {
N310 = 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(t311)->set(this, 1000);
mac_timers->get(safe_reset_timer)->set(this, 10);