new set of cppcheck fixes

This commit is contained in:
frtabu
2019-02-12 10:12:07 +01:00
parent 63143b87a7
commit 824d2b478a
58 changed files with 13452 additions and 15300 deletions
+70 -80
View File
@@ -17,10 +17,10 @@
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
*/
/*! \file flexran_agent_timer.c
* \brief FlexRAN Timer
* \brief FlexRAN Timer
* \author shahab SHARIAT BAGHERI
* \date 2017
* \version 0.1
@@ -35,23 +35,23 @@
//struct flexran_agent_map agent_map;
flexran_agent_timer_instance_t timer_instance;
int agent_timer_init = 0;
err_code_t flexran_agent_init_timer(void){
err_code_t flexran_agent_init_timer(void) {
LOG_I(FLEXRAN_AGENT, "init RB tree\n");
if (!agent_timer_init) {
RB_INIT(&timer_instance.flexran_agent_head);
agent_timer_init = 1;
}
return PROTOCOL__FLEXRAN_ERR__NO_ERR;
return PROTOCOL__FLEXRAN_ERR__NO_ERR;
}
RB_GENERATE(flexran_agent_map, flexran_agent_timer_element_s, entry, flexran_agent_compare_timer);
/* The timer_id might not be the best choice for the comparison */
int flexran_agent_compare_timer(struct flexran_agent_timer_element_s *a, struct flexran_agent_timer_element_s *b){
int flexran_agent_compare_timer(struct flexran_agent_timer_element_s *a, struct flexran_agent_timer_element_s *b) {
if (a->timer_id < b->timer_id) return -1;
if (a->timer_id > b->timer_id) return 1;
// equal timers
@@ -59,52 +59,53 @@ int flexran_agent_compare_timer(struct flexran_agent_timer_element_s *a, struct
}
err_code_t flexran_agent_create_timer(uint32_t interval_sec,
uint32_t interval_usec,
agent_id_t agent_id,
instance_t instance,
uint32_t timer_type,
xid_t xid,
flexran_agent_timer_callback_t cb,
void* timer_args,
long *timer_id){
uint32_t interval_usec,
agent_id_t agent_id,
instance_t instance,
uint32_t timer_type,
xid_t xid,
flexran_agent_timer_callback_t cb,
void *timer_args,
long *timer_id) {
struct flexran_agent_timer_element_s *e = calloc(1, sizeof(*e));
DevAssert(e != NULL);
//uint32_t timer_id;
//uint32_t timer_id;
int ret=-1;
if ((interval_sec == 0) && (interval_usec == 0 ))
if ((interval_sec == 0) && (interval_usec == 0 )) {
free(e);
return TIMER_NULL;
if (timer_type >= FLEXRAN_AGENT_TIMER_TYPE_MAX)
return TIMER_TYPE_INVALIDE;
if (timer_type == FLEXRAN_AGENT_TIMER_TYPE_ONESHOT){
ret = timer_setup(interval_sec,
interval_usec,
TASK_FLEXRAN_AGENT,
instance,
TIMER_ONE_SHOT,
timer_args,
timer_id);
e->type = TIMER_ONE_SHOT;
}
else if (timer_type == FLEXRAN_AGENT_TIMER_TYPE_PERIODIC ){
ret = timer_setup(interval_sec,
interval_usec,
TASK_FLEXRAN_AGENT,
instance,
TIMER_PERIODIC,
timer_args,
timer_id);
if (timer_type >= FLEXRAN_AGENT_TIMER_TYPE_MAX) {
free(e);
return TIMER_TYPE_INVALIDE;
}
if (timer_type == FLEXRAN_AGENT_TIMER_TYPE_ONESHOT) {
ret = timer_setup(interval_sec,
interval_usec,
TASK_FLEXRAN_AGENT,
instance,
TIMER_ONE_SHOT,
timer_args,
timer_id);
e->type = TIMER_ONE_SHOT;
} else if (timer_type == FLEXRAN_AGENT_TIMER_TYPE_PERIODIC ) {
ret = timer_setup(interval_sec,
interval_usec,
TASK_FLEXRAN_AGENT,
instance,
TIMER_PERIODIC,
timer_args,
timer_id);
e->type = TIMER_PERIODIC;
}
if (ret < 0 ) {
return TIMER_SETUP_FAILED;
free(e);
return TIMER_SETUP_FAILED;
}
e->agent_id = agent_id;
@@ -112,19 +113,16 @@ err_code_t flexran_agent_create_timer(uint32_t interval_sec,
e->state = FLEXRAN_AGENT_TIMER_STATE_ACTIVE;
e->timer_id = *timer_id;
e->xid = xid;
e->timer_args = timer_args;
e->timer_args = timer_args;
e->cb = cb;
/*element should be a real pointer*/
RB_INSERT(flexran_agent_map, &timer_instance.flexran_agent_head, e);
RB_INSERT(flexran_agent_map, &timer_instance.flexran_agent_head, e);
LOG_I(FLEXRAN_AGENT,"Created a new timer with id 0x%lx for agent %d, instance %d \n",
e->timer_id, e->agent_id, e->instance);
return 0;
e->timer_id, e->agent_id, e->instance);
return 0;
}
err_code_t flexran_agent_destroy_timer(long timer_id){
err_code_t flexran_agent_destroy_timer(long timer_id) {
struct flexran_agent_timer_element_s *e = get_timer_entry(timer_id);
if (e != NULL ) {
@@ -132,13 +130,12 @@ err_code_t flexran_agent_destroy_timer(long timer_id){
flexran_agent_destroy_flexran_message(e->timer_args->msg);
free(e);
}
if (timer_remove(timer_id) < 0 )
goto error;
return 0;
error:
if (timer_remove(timer_id) < 0 )
goto error;
return 0;
error:
LOG_E(FLEXRAN_AGENT, "timer can't be removed\n");
return TIMER_REMOVED_FAILED ;
}
@@ -152,66 +149,59 @@ err_code_t flexran_agent_destroy_timer_by_task_id(xid_t xid) {
RB_REMOVE(flexran_agent_map, &timer_instance.flexran_agent_head, e);
flexran_agent_destroy_flexran_message(e->timer_args->msg);
free(e);
if (timer_remove(timer_id) < 0 ) {
goto error;
if (timer_remove(timer_id) < 0 ) {
goto error;
}
}
}
return 0;
error:
error:
LOG_E(FLEXRAN_AGENT, "timer can't be removed\n");
return TIMER_REMOVED_FAILED ;
}
err_code_t flexran_agent_destroy_timers(void){
err_code_t flexran_agent_destroy_timers(void) {
struct flexran_agent_timer_element_s *e = NULL;
RB_FOREACH(e, flexran_agent_map, &timer_instance.flexran_agent_head) {
RB_REMOVE(flexran_agent_map, &timer_instance.flexran_agent_head, e);
timer_remove(e->timer_id);
flexran_agent_destroy_flexran_message(e->timer_args->msg);
free(e);
}
}
return 0;
}
void flexran_agent_sleep_until(struct timespec *ts, int delay) {
ts->tv_nsec += delay;
if(ts->tv_nsec >= 1000*1000*1000){
if(ts->tv_nsec >= 1000*1000*1000) {
ts->tv_nsec -= 1000*1000*1000;
ts->tv_sec++;
}
clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, ts, NULL);
}
err_code_t flexran_agent_stop_timer(long timer_id){
err_code_t flexran_agent_stop_timer(long timer_id) {
struct flexran_agent_timer_element_s *e=NULL;
struct flexran_agent_timer_element_s search;
memset(&search, 0, sizeof(struct flexran_agent_timer_element_s));
search.timer_id = timer_id;
e = RB_FIND(flexran_agent_map, &timer_instance.flexran_agent_head, &search);
if (e != NULL ) {
e->state = FLEXRAN_AGENT_TIMER_STATE_STOPPED;
}
timer_remove(timer_id);
return 0;
}
struct flexran_agent_timer_element_s * get_timer_entry(long timer_id) {
struct flexran_agent_timer_element_s *get_timer_entry(long timer_id) {
struct flexran_agent_timer_element_s search;
memset(&search, 0, sizeof(struct flexran_agent_timer_element_s));
search.timer_id = timer_id;
return RB_FIND(flexran_agent_map, &timer_instance.flexran_agent_head, &search);
return RB_FIND(flexran_agent_map, &timer_instance.flexran_agent_head, &search);
}