timer library update
This commit is contained in:
parent
028ac433ff
commit
5663f64cbb
|
@ -41,13 +41,18 @@ extern "C" {
|
|||
#define event_get_param7(__ptr_e) ((__ptr_e)->param7)
|
||||
#define event_get_param8(__ptr_e) ((__ptr_e)->param8)
|
||||
|
||||
#define event_timer(__tm_service, __ptr_e, __duration, __param) \
|
||||
#define timer_create(__tm_service, __ptr_e, __duration) \
|
||||
event_timer_create((__tm_service), TIMER_TYPE_ONE_SHOT, \
|
||||
(__duration), (__ptr_e), (__param))
|
||||
|
||||
#define event_timer_periodic(__tm_service, __ptr_e, __duration, __param) \
|
||||
(__duration), (__ptr_e))
|
||||
#define periodic_timer_create(__tm_service, __ptr_e, __duration) \
|
||||
event_timer_create((__tm_service), TIMER_TYPE_PERIODIC, \
|
||||
(__duration), (__ptr_e), (__param))
|
||||
(__duration), (__ptr_e))
|
||||
|
||||
#define timer_set_param1(__ptr_e, __param) tm_set_param2(__ptr_e, __param);
|
||||
#define timer_set_param2(__ptr_e, __param) tm_set_param3(__ptr_e, __param);
|
||||
#define timer_set_param3(__ptr_e, __param) tm_set_param4(__ptr_e, __param);
|
||||
#define timer_set_param4(__ptr_e, __param) tm_set_param5(__ptr_e, __param);
|
||||
#define timer_set_param5(__ptr_e, __param) tm_set_param6(__ptr_e, __param);
|
||||
|
||||
typedef struct {
|
||||
fsm_event_t event;
|
||||
|
@ -101,9 +106,8 @@ CORE_DECLARE(status_t) event_timedrecv(
|
|||
/**
|
||||
* Create a timer
|
||||
*/
|
||||
CORE_DECLARE(tm_block_id) event_timer_create(
|
||||
tm_service_t *tm_service, tm_type_e type, c_uint32_t duration,
|
||||
c_uintptr_t event, c_uintptr_t param);
|
||||
CORE_DECLARE(tm_block_id) event_timer_create(tm_service_t *tm_service,
|
||||
tm_type_e type, c_uint32_t duration, c_uintptr_t event);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -23,15 +23,19 @@ typedef struct _tm_service_t {
|
|||
typedef c_uintptr_t tm_block_id;
|
||||
|
||||
typedef void (*expire_func_t)(c_uintptr_t data,
|
||||
c_uintptr_t arg1, c_uintptr_t arg2, c_uintptr_t arg3);
|
||||
c_uintptr_t param1, c_uintptr_t param2, c_uintptr_t param3,
|
||||
c_uintptr_t param4, c_uintptr_t param5, c_uintptr_t param6);
|
||||
|
||||
typedef struct _tm_desc_t {
|
||||
tm_type_e type;
|
||||
c_uint32_t duration;
|
||||
expire_func_t expire_func;
|
||||
c_uintptr_t arg1;
|
||||
c_uintptr_t arg2;
|
||||
c_uintptr_t arg3;
|
||||
c_uintptr_t param1;
|
||||
c_uintptr_t param2;
|
||||
c_uintptr_t param3;
|
||||
c_uintptr_t param4;
|
||||
c_uintptr_t param5;
|
||||
c_uintptr_t param6;
|
||||
} tm_desc_t;
|
||||
|
||||
CORE_DECLARE(status_t) tm_init(void);
|
||||
|
@ -43,13 +47,16 @@ CORE_DECLARE(void) tm_service_init(tm_service_t *tm_service);
|
|||
CORE_DECLARE(status_t) tm_execute_tm_service(
|
||||
tm_service_t *p_tm_s, c_uintptr_t data);
|
||||
|
||||
CORE_DECLARE(tm_block_id) tm_create(tm_service_t *tm_service);
|
||||
CORE_DECLARE(tm_block_id) tm_create(tm_service_t *tm_service,
|
||||
tm_type_e type, c_uint32_t duration, expire_func_t expire_func);
|
||||
CORE_DECLARE(void) tm_delete(tm_block_id id);
|
||||
CORE_DECLARE(status_t) tm_set(tm_block_id id, tm_type_e type,
|
||||
c_uint32_t duration, expire_func_t expire_func,
|
||||
c_uintptr_t arg1, c_uintptr_t arg2, c_uintptr_t arg3);
|
||||
CORE_DECLARE(status_t) tm_set_duration(tm_block_id id, c_uint32_t duration);
|
||||
CORE_DECLARE(status_t) tm_set_by_desc(tm_block_id id, tm_desc_t *desc);
|
||||
CORE_DECLARE(status_t) tm_set_param1(tm_block_id id, c_uintptr_t param);
|
||||
CORE_DECLARE(status_t) tm_set_param2(tm_block_id id, c_uintptr_t param);
|
||||
CORE_DECLARE(status_t) tm_set_param3(tm_block_id id, c_uintptr_t param);
|
||||
CORE_DECLARE(status_t) tm_set_param4(tm_block_id id, c_uintptr_t param);
|
||||
CORE_DECLARE(status_t) tm_set_param5(tm_block_id id, c_uintptr_t param);
|
||||
CORE_DECLARE(status_t) tm_set_param6(tm_block_id id, c_uintptr_t param);
|
||||
CORE_DECLARE(status_t) tm_start(tm_block_id id);
|
||||
CORE_DECLARE(status_t) tm_stop(tm_block_id id);
|
||||
|
||||
|
|
|
@ -66,15 +66,20 @@ status_t event_timedrecv(msgq_id queue_id, event_t *e, c_time_t timeout)
|
|||
return rv;
|
||||
}
|
||||
|
||||
void* event_timer_expire_func(
|
||||
c_uintptr_t queue_id, c_uintptr_t event, c_uintptr_t param)
|
||||
void* event_timer_expire_func(c_uintptr_t queue_id, c_uintptr_t event,
|
||||
c_uintptr_t param1, c_uintptr_t param2, c_uintptr_t param3,
|
||||
c_uintptr_t param4, c_uintptr_t param5)
|
||||
{
|
||||
event_t e;
|
||||
status_t rv;
|
||||
|
||||
d_assert(queue_id, return NULL, "Null param");
|
||||
event_set(&e, event);
|
||||
event_set_param1(&e, param);
|
||||
event_set_param1(&e, param1);
|
||||
event_set_param2(&e, param2);
|
||||
event_set_param3(&e, param3);
|
||||
event_set_param4(&e, param4);
|
||||
event_set_param5(&e, param5);
|
||||
|
||||
rv = event_send(queue_id, &e);
|
||||
if (rv != CORE_OK)
|
||||
|
@ -86,15 +91,14 @@ void* event_timer_expire_func(
|
|||
}
|
||||
|
||||
tm_block_id event_timer_create(tm_service_t *tm_service, tm_type_e type,
|
||||
c_uint32_t duration, c_uintptr_t event, c_uintptr_t param)
|
||||
c_uint32_t duration, c_uintptr_t event)
|
||||
{
|
||||
tm_block_id id;
|
||||
|
||||
id = tm_create(tm_service);
|
||||
id = tm_create(tm_service,
|
||||
type, duration, (expire_func_t)event_timer_expire_func);
|
||||
tm_set_param1(id, event);
|
||||
d_assert(id, return 0, "tm_create() failed");
|
||||
|
||||
tm_set(id, type, duration, (expire_func_t)event_timer_expire_func,
|
||||
event, param, 0);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
|
|
@ -12,9 +12,12 @@ typedef struct _tm_block_t {
|
|||
c_uint32_t expire_time;
|
||||
|
||||
expire_func_t expire_func;
|
||||
c_uintptr_t arg1;
|
||||
c_uintptr_t arg2;
|
||||
c_uintptr_t arg3;
|
||||
c_uintptr_t param1;
|
||||
c_uintptr_t param2;
|
||||
c_uintptr_t param3;
|
||||
c_uintptr_t param4;
|
||||
c_uintptr_t param5;
|
||||
c_uintptr_t param6;
|
||||
|
||||
tm_type_e type;
|
||||
c_uint8_t running;
|
||||
|
@ -71,7 +74,8 @@ status_t tm_execute_tm_service(tm_service_t *p_tm_s, c_uintptr_t data)
|
|||
if(tm->expire_time < cur_time)
|
||||
{
|
||||
/* execute expiry function */
|
||||
tm->expire_func(data, tm->arg1, tm->arg2, tm->arg3);
|
||||
tm->expire_func(data, tm->param1, tm->param2, tm->param3,
|
||||
tm->param4, tm->param5, tm->param6);
|
||||
|
||||
/* remove this tm_block from the active list */
|
||||
_tm_remove(&(p_tm_s->active_list), tm);
|
||||
|
@ -135,7 +139,8 @@ static void _tm_free(tm_block_t *tm)
|
|||
|
||||
}
|
||||
|
||||
tm_block_id tm_create(tm_service_t *tm_service)
|
||||
tm_block_id tm_create(tm_service_t *tm_service,
|
||||
tm_type_e type, c_uint32_t duration, expire_func_t expire_func)
|
||||
{
|
||||
tm_block_t *tm = NULL;
|
||||
tm = _tm_get();
|
||||
|
@ -145,6 +150,10 @@ tm_block_id tm_create(tm_service_t *tm_service)
|
|||
|
||||
_tm_add(&(tm->tm_s->idle_list), tm);
|
||||
|
||||
tm->type = type;
|
||||
tm->duration = duration;
|
||||
tm->expire_func = expire_func;
|
||||
|
||||
return (tm_block_id)tm;
|
||||
}
|
||||
|
||||
|
@ -164,23 +173,6 @@ void tm_delete(tm_block_id id)
|
|||
return;
|
||||
}
|
||||
|
||||
status_t tm_set(
|
||||
tm_block_id id, tm_type_e type, c_uint32_t duration,
|
||||
expire_func_t expire_func,
|
||||
c_uintptr_t arg1, c_uintptr_t arg2, c_uintptr_t arg3)
|
||||
{
|
||||
tm_block_t *tm = (tm_block_t *)id;
|
||||
|
||||
tm->type = type;
|
||||
tm->duration = duration;
|
||||
tm->expire_func = expire_func;
|
||||
tm->arg1 = arg1;
|
||||
tm->arg2 = arg2;
|
||||
tm->arg3 = arg3;
|
||||
|
||||
return CORE_OK;
|
||||
}
|
||||
|
||||
status_t tm_set_duration(tm_block_id id, c_uint32_t duration)
|
||||
{
|
||||
tm_block_t *tm = (tm_block_t *)id;
|
||||
|
@ -190,16 +182,56 @@ status_t tm_set_duration(tm_block_id id, c_uint32_t duration)
|
|||
return CORE_OK;
|
||||
}
|
||||
|
||||
status_t tm_set_by_desc(tm_block_id id, tm_desc_t *desc)
|
||||
status_t tm_set_param1(tm_block_id id, c_uintptr_t param)
|
||||
{
|
||||
tm_block_t *tm = (tm_block_t *)id;
|
||||
|
||||
tm->type = desc->type;
|
||||
tm->duration = desc->duration;
|
||||
tm->expire_func = desc->expire_func;
|
||||
tm->arg1 = desc->arg1;
|
||||
tm->arg2 = desc->arg2;
|
||||
tm->arg3 = desc->arg3;
|
||||
tm->param1 = param;
|
||||
|
||||
return CORE_OK;
|
||||
}
|
||||
|
||||
status_t tm_set_param2(tm_block_id id, c_uintptr_t param)
|
||||
{
|
||||
tm_block_t *tm = (tm_block_t *)id;
|
||||
|
||||
tm->param2 = param;
|
||||
|
||||
return CORE_OK;
|
||||
}
|
||||
|
||||
status_t tm_set_param3(tm_block_id id, c_uintptr_t param)
|
||||
{
|
||||
tm_block_t *tm = (tm_block_t *)id;
|
||||
|
||||
tm->param3 = param;
|
||||
|
||||
return CORE_OK;
|
||||
}
|
||||
|
||||
status_t tm_set_param4(tm_block_id id, c_uintptr_t param)
|
||||
{
|
||||
tm_block_t *tm = (tm_block_t *)id;
|
||||
|
||||
tm->param4 = param;
|
||||
|
||||
return CORE_OK;
|
||||
}
|
||||
|
||||
status_t tm_set_param5(tm_block_id id, c_uintptr_t param)
|
||||
{
|
||||
tm_block_t *tm = (tm_block_t *)id;
|
||||
|
||||
tm->param5 = param;
|
||||
|
||||
return CORE_OK;
|
||||
}
|
||||
|
||||
status_t tm_set_param6(tm_block_id id, c_uintptr_t param)
|
||||
{
|
||||
tm_block_t *tm = (tm_block_t *)id;
|
||||
|
||||
tm->param6 = param;
|
||||
|
||||
return CORE_OK;
|
||||
}
|
||||
|
|
|
@ -26,17 +26,19 @@ test_timer_eliment timer_eliment[] ={
|
|||
|
||||
|
||||
void test_expire_func_1(c_uintptr_t data,
|
||||
c_uintptr_t arg1, c_uintptr_t arg2, c_uintptr_t arg3)
|
||||
c_uintptr_t param1, c_uintptr_t param2, c_uintptr_t param3,
|
||||
c_uintptr_t param4, c_uintptr_t param5, c_uintptr_t param6)
|
||||
{
|
||||
c_uint32_t index = arg2;
|
||||
c_uint32_t index = param2;
|
||||
|
||||
expire_check[index] = TRUE;
|
||||
}
|
||||
|
||||
void test_expire_func_2(c_uintptr_t data,
|
||||
c_uintptr_t arg1, c_uintptr_t arg2, c_uintptr_t arg3)
|
||||
c_uintptr_t param1, c_uintptr_t param2, c_uintptr_t param3,
|
||||
c_uintptr_t param4, c_uintptr_t param5, c_uintptr_t param6)
|
||||
{
|
||||
c_uint32_t index = arg2;
|
||||
c_uint32_t index = param2;
|
||||
|
||||
expire_check[index]++;
|
||||
}
|
||||
|
@ -77,9 +79,11 @@ static void timer_test_1(abts_case *tc, void *data)
|
|||
|
||||
for(n = 0; n < sizeof(timer_eliment) / sizeof(test_timer_eliment); n++)
|
||||
{
|
||||
id_array[n] = tm_create(&tm_service);
|
||||
tm_set(id_array[n], TIMER_TYPE_ONE_SHOT, timer_eliment[n].duration,
|
||||
test_expire_func_1, (c_uintptr_t)id_array[n], n, 0);
|
||||
id_array[n] = tm_create(&tm_service, TIMER_TYPE_ONE_SHOT,
|
||||
timer_eliment[n].duration, test_expire_func_1);
|
||||
|
||||
tm_set_param1(id_array[n], (c_uintptr_t)id_array[n]);
|
||||
tm_set_param2(id_array[n], n);
|
||||
}
|
||||
|
||||
|
||||
|
@ -275,9 +279,10 @@ static void timer_test_2(abts_case *tc, void *data)
|
|||
tm_num[tm_idx]++;
|
||||
duration += (TEST_TIMER_PRECISION >> 1);
|
||||
|
||||
id_array[n] = tm_create(&tm_service);
|
||||
tm_set(id_array[n], TIMER_TYPE_ONE_SHOT, duration,
|
||||
test_expire_func_2, (c_uintptr_t)id_array[n], tm_idx, 0);
|
||||
id_array[n] = tm_create(&tm_service,
|
||||
TIMER_TYPE_ONE_SHOT, duration, test_expire_func_2);
|
||||
tm_set_param1(id_array[n], (c_uintptr_t)id_array[n]);
|
||||
tm_set_param2(id_array[n], tm_idx);
|
||||
}
|
||||
|
||||
for(n = 0; n < TEST_TIMER_NUM; n++)
|
||||
|
@ -329,10 +334,10 @@ static void timer_test_3(abts_case *tc, void *data)
|
|||
id_duration[n] = duration;
|
||||
duration += (TEST_TIMER_PRECISION >> 1);
|
||||
|
||||
|
||||
id_array[n] = tm_create(&tm_service);
|
||||
tm_set(id_array[n], TIMER_TYPE_ONE_SHOT, duration,
|
||||
test_expire_func_2, (c_uint32_t)id_array[n], tm_idx, 0);
|
||||
id_array[n] = tm_create(&tm_service,
|
||||
TIMER_TYPE_ONE_SHOT, duration, test_expire_func_2);
|
||||
tm_set_param1(id_array[n], (c_uintptr_t)id_array[n]);
|
||||
tm_set_param2(id_array[n], tm_idx);
|
||||
}
|
||||
|
||||
for(n = 0; n < TEST_TIMER_NUM; n++)
|
||||
|
|
|
@ -91,17 +91,19 @@ gtp_xact_t *gtp_xact_local_create(
|
|||
|
||||
if (g_response_event)
|
||||
{
|
||||
xact->tm_response = event_timer(g_tm_service,
|
||||
g_response_event, GTP_T3_RESPONSE_DURATION, xact->index);
|
||||
xact->tm_response = timer_create(g_tm_service,
|
||||
g_response_event, GTP_T3_RESPONSE_DURATION);
|
||||
d_assert(xact->tm_response, return NULL, "Timer allocation failed");
|
||||
timer_set_param1(xact->tm_response, xact->index);
|
||||
xact->response_rcount = GTP_T3_RESPONSE_RETRY_COUNT;
|
||||
}
|
||||
|
||||
if (g_holding_event)
|
||||
{
|
||||
xact->tm_holding = event_timer(g_tm_service,
|
||||
g_holding_event, GTP_T3_DUPLICATED_DURATION, xact->index);
|
||||
xact->tm_holding = timer_create(g_tm_service,
|
||||
g_holding_event, GTP_T3_DUPLICATED_DURATION);
|
||||
d_assert(xact->tm_holding, return NULL, "Timer allocation failed");
|
||||
timer_set_param1(xact->tm_holding, xact->index);
|
||||
xact->holding_rcount = GTP_T3_DUPLICATED_RETRY_COUNT;
|
||||
}
|
||||
|
||||
|
@ -135,17 +137,19 @@ gtp_xact_t *gtp_xact_remote_create(gtp_node_t *gnode, c_uint32_t sqn)
|
|||
|
||||
if (g_response_event)
|
||||
{
|
||||
xact->tm_response = event_timer(g_tm_service,
|
||||
g_response_event, GTP_T3_RESPONSE_DURATION, xact->index);
|
||||
xact->tm_response = timer_create(g_tm_service,
|
||||
g_response_event, GTP_T3_RESPONSE_DURATION);
|
||||
d_assert(xact->tm_response, return NULL, "Timer allocation failed");
|
||||
timer_set_param1(xact->tm_response, xact->index);
|
||||
xact->response_rcount = GTP_T3_RESPONSE_RETRY_COUNT;
|
||||
}
|
||||
|
||||
if (g_holding_event)
|
||||
{
|
||||
xact->tm_holding = event_timer(g_tm_service,
|
||||
g_holding_event, GTP_T3_DUPLICATED_DURATION, xact->index);
|
||||
xact->tm_holding = timer_create(g_tm_service,
|
||||
g_holding_event, GTP_T3_DUPLICATED_DURATION);
|
||||
d_assert(xact->tm_holding, return NULL, "Timer allocation failed");
|
||||
timer_set_param1(xact->tm_holding, xact->index);
|
||||
xact->holding_rcount = GTP_T3_DUPLICATED_RETRY_COUNT;
|
||||
}
|
||||
|
||||
|
|
|
@ -1153,8 +1153,10 @@ mme_ue_t* mme_ue_add(enb_ue_t *enb_ue)
|
|||
mme_ue->mme_s11_addr = mme_self()->s11_addr;
|
||||
|
||||
/* Create t3413 timer */
|
||||
mme_ue->t3413 = event_timer(&self.tm_service, MME_EVT_EMM_T3413,
|
||||
self.t3413_value * 1000, mme_ue->index);
|
||||
mme_ue->t3413 = timer_create(&self.tm_service, MME_EVT_EMM_T3413,
|
||||
self.t3413_value * 1000);
|
||||
d_assert(mme_ue->t3413, return NULL, "Null param");
|
||||
timer_set_param1(mme_ue->t3413, mme_ue->index);
|
||||
|
||||
event_set_param1(&e, (c_uintptr_t)mme_ue->index);
|
||||
fsm_create(&mme_ue->sm, emm_state_initial, emm_state_final);
|
||||
|
|
Loading…
Reference in New Issue