Added mutex for ue_rem/buffer access for more safety

master
Ismael Gomez 7 years ago
parent 45cae1d1ab
commit fa4d14652d

@ -217,7 +217,7 @@ private:
bool configured; bool configured;
pthread_mutex_t mutex; pthread_mutex_t mutex, mutex2;
}; };

@ -64,6 +64,7 @@ sched::sched() : bc_aggr_level(0), rar_aggr_level(0), avail_rbg(0), P(0), start_
} }
pthread_mutex_init(&mutex, NULL); pthread_mutex_init(&mutex, NULL);
pthread_mutex_init(&mutex2, NULL);
reset(); reset();
} }
@ -71,6 +72,7 @@ sched::~sched()
{ {
srslte_regs_free(&regs); srslte_regs_free(&regs);
pthread_mutex_destroy(&mutex); pthread_mutex_destroy(&mutex);
pthread_mutex_destroy(&mutex2);
} }
void sched::init(rrc_interface_mac *rrc_, srslte::log* log) void sched::init(rrc_interface_mac *rrc_, srslte::log* log)
@ -173,6 +175,7 @@ int sched::ue_cfg(uint16_t rnti, sched_interface::ue_cfg_t *ue_cfg)
int sched::ue_rem(uint16_t rnti) int sched::ue_rem(uint16_t rnti)
{ {
pthread_mutex_lock(&mutex); pthread_mutex_lock(&mutex);
pthread_mutex_lock(&mutex2);
int ret = 0; int ret = 0;
if (ue_db.count(rnti)) { if (ue_db.count(rnti)) {
ue_db.erase(rnti); ue_db.erase(rnti);
@ -180,6 +183,7 @@ int sched::ue_rem(uint16_t rnti)
Error("User rnti=0x%x not found\n", rnti); Error("User rnti=0x%x not found\n", rnti);
ret = -1; ret = -1;
} }
pthread_mutex_unlock(&mutex2);
pthread_mutex_unlock(&mutex); pthread_mutex_unlock(&mutex);
return ret; return ret;
} }
@ -217,6 +221,7 @@ int sched::bearer_ue_cfg(uint16_t rnti, uint32_t lc_id, sched_interface::ue_bear
int sched::bearer_ue_rem(uint16_t rnti, uint32_t lc_id) int sched::bearer_ue_rem(uint16_t rnti, uint32_t lc_id)
{ {
pthread_mutex_lock(&mutex); pthread_mutex_lock(&mutex);
pthread_mutex_lock(&mutex2);
int ret = 0; int ret = 0;
if (ue_db.count(rnti)) { if (ue_db.count(rnti)) {
ue_db[rnti].rem_bearer(lc_id); ue_db[rnti].rem_bearer(lc_id);
@ -224,6 +229,7 @@ int sched::bearer_ue_rem(uint16_t rnti, uint32_t lc_id)
Error("User rnti=0x%x not found\n", rnti); Error("User rnti=0x%x not found\n", rnti);
ret = -1; ret = -1;
} }
pthread_mutex_unlock(&mutex2);
pthread_mutex_unlock(&mutex); pthread_mutex_unlock(&mutex);
return ret; return ret;
} }
@ -259,9 +265,13 @@ uint32_t sched::get_ul_buffer(uint16_t rnti)
* Ideally we would like the scheduler to query the RLC for buffer states in order to get the most updated * Ideally we would like the scheduler to query the RLC for buffer states in order to get the most updated
* buffer state with the minimum overhead. However, the current architecture is designed to be compliant * buffer state with the minimum overhead. However, the current architecture is designed to be compliant
* with the FAPI interface * with the FAPI interface
*
* We add a new mutex used only in ue_rem to avoid the UE being removed in between the access to
* ue_db.count() and the access to the std::map.
*/ */
int sched::dl_rlc_buffer_state(uint16_t rnti, uint32_t lc_id, uint32_t tx_queue, uint32_t retx_queue) int sched::dl_rlc_buffer_state(uint16_t rnti, uint32_t lc_id, uint32_t tx_queue, uint32_t retx_queue)
{ {
pthread_mutex_lock(&mutex2);
int ret = 0; int ret = 0;
if (ue_db.count(rnti)) { if (ue_db.count(rnti)) {
ue_db[rnti].dl_buffer_state(lc_id, tx_queue, retx_queue); ue_db[rnti].dl_buffer_state(lc_id, tx_queue, retx_queue);
@ -269,12 +279,14 @@ int sched::dl_rlc_buffer_state(uint16_t rnti, uint32_t lc_id, uint32_t tx_queue,
Error("User rnti=0x%x not found\n", rnti); Error("User rnti=0x%x not found\n", rnti);
ret = -1; ret = -1;
} }
pthread_mutex_unlock(&mutex2);
return ret; return ret;
} }
/* \Warning Read comment in dl_rlc_buffer_state() */
int sched::dl_mac_buffer_state(uint16_t rnti, uint32_t ce_code) int sched::dl_mac_buffer_state(uint16_t rnti, uint32_t ce_code)
{ {
pthread_mutex_lock(&mutex); pthread_mutex_lock(&mutex2);
int ret = 0; int ret = 0;
if (ue_db.count(rnti)) { if (ue_db.count(rnti)) {
ue_db[rnti].mac_buffer_state(ce_code); ue_db[rnti].mac_buffer_state(ce_code);
@ -282,7 +294,7 @@ int sched::dl_mac_buffer_state(uint16_t rnti, uint32_t ce_code)
Error("User rnti=0x%x not found\n", rnti); Error("User rnti=0x%x not found\n", rnti);
ret = -1; ret = -1;
} }
pthread_mutex_unlock(&mutex); pthread_mutex_unlock(&mutex2);
return ret; return ret;
} }

Loading…
Cancel
Save