|
|
|
@@ -43,13 +43,7 @@ Description Timer utilities
|
|
|
|
|
#include <string.h> // memset
|
|
|
|
|
#include <stdlib.h> // malloc, free
|
|
|
|
|
#include <sys/time.h> // setitimer
|
|
|
|
|
|
|
|
|
|
#if defined(ENABLE_ITTI)
|
|
|
|
|
# include "intertask_interface.h"
|
|
|
|
|
#else
|
|
|
|
|
# include <signal.h>
|
|
|
|
|
# include <time.h> // clock_gettime
|
|
|
|
|
#endif
|
|
|
|
|
#include "intertask_interface.h"
|
|
|
|
|
#include "nas_timer.h"
|
|
|
|
|
#include "commonDef.h"
|
|
|
|
|
#include "msc.h"
|
|
|
|
@@ -69,11 +63,7 @@ Description Timer utilities
|
|
|
|
|
* value when the timer entry was allocated.
|
|
|
|
|
*/
|
|
|
|
|
typedef struct {
|
|
|
|
|
#if defined(ENABLE_ITTI)
|
|
|
|
|
long timer_id; /* Timer id returned by the timer API from ITTI */
|
|
|
|
|
#else
|
|
|
|
|
pthread_t pid; /* Thread identifier of the callback */
|
|
|
|
|
#endif
|
|
|
|
|
long timer_id; /* Timer id returned by the timer API from ITTI */
|
|
|
|
|
|
|
|
|
|
struct timeval itv; /* Initial interval timer value */
|
|
|
|
|
struct timeval tv; /* Interval timer value */
|
|
|
|
@@ -105,10 +95,6 @@ typedef struct {
|
|
|
|
|
#define TIMER_DATABASE_SIZE 256
|
|
|
|
|
timer_queue_t tq[TIMER_DATABASE_SIZE];
|
|
|
|
|
timer_queue_t *head;/* Pointer to the first timer entry to be fired */
|
|
|
|
|
|
|
|
|
|
#if !defined(ENABLE_ITTI)
|
|
|
|
|
pthread_mutex_t mutex;
|
|
|
|
|
#endif
|
|
|
|
|
} nas_timer_database_t;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@@ -118,25 +104,15 @@ static nas_timer_database_t _nas_timer_db = {
|
|
|
|
|
0,
|
|
|
|
|
{},
|
|
|
|
|
NULL
|
|
|
|
|
#if !defined(ENABLE_ITTI)
|
|
|
|
|
, PTHREAD_MUTEX_INITIALIZER
|
|
|
|
|
#endif
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#if defined(ENABLE_ITTI)
|
|
|
|
|
#define nas_timer_lock_db()
|
|
|
|
|
#define nas_timer_unlock_db()
|
|
|
|
|
#else
|
|
|
|
|
#define nas_timer_lock_db() pthread_mutex_lock(&_nas_timer_db.mutex)
|
|
|
|
|
#define nas_timer_unlock_db() pthread_mutex_unlock(&_nas_timer_db.mutex)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The handler executed whenever the system timer expires
|
|
|
|
|
*/
|
|
|
|
|
#if !defined(ENABLE_ITTI)
|
|
|
|
|
static void _nas_timer_handler(int signal);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* -----------------------------------------------------------------------------
|
|
|
|
@@ -191,33 +167,6 @@ int nas_timer_init(void)
|
|
|
|
|
/* Initialize the timer database */
|
|
|
|
|
_nas_timer_db_init();
|
|
|
|
|
|
|
|
|
|
#if !defined(ENABLE_ITTI)
|
|
|
|
|
/* Setup the timer database handler */
|
|
|
|
|
struct sigaction act;
|
|
|
|
|
|
|
|
|
|
(void) memset (&act, 0, sizeof (act));
|
|
|
|
|
(void) sigfillset (&act.sa_mask);
|
|
|
|
|
(void) sigdelset (&act.sa_mask, SIGHUP);
|
|
|
|
|
(void) sigdelset (&act.sa_mask, SIGINT);
|
|
|
|
|
(void) sigdelset (&act.sa_mask, SIGTERM);
|
|
|
|
|
(void) sigdelset (&act.sa_mask, SIGILL);
|
|
|
|
|
(void) sigdelset (&act.sa_mask, SIGTRAP);
|
|
|
|
|
(void) sigdelset (&act.sa_mask, SIGIOT);
|
|
|
|
|
# ifndef LINUX
|
|
|
|
|
(void) sigdelset (&act.sa_mask, SIGEMT);
|
|
|
|
|
# endif
|
|
|
|
|
(void) sigdelset (&act.sa_mask, SIGFPE);
|
|
|
|
|
(void) sigdelset (&act.sa_mask, SIGBUS);
|
|
|
|
|
(void) sigdelset (&act.sa_mask, SIGSEGV);
|
|
|
|
|
(void) sigdelset (&act.sa_mask, SIGSYS);
|
|
|
|
|
|
|
|
|
|
act.sa_handler = _nas_timer_handler;
|
|
|
|
|
|
|
|
|
|
if ( sigaction (SIGALRM, &act, 0) < 0 ) {
|
|
|
|
|
return (RETURNerror);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
return (RETURNok);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -243,10 +192,8 @@ int nas_timer_start(long sec, nas_timer_callback_t cb, void *args)
|
|
|
|
|
{
|
|
|
|
|
int id;
|
|
|
|
|
nas_timer_entry_t *te;
|
|
|
|
|
#if defined(ENABLE_ITTI)
|
|
|
|
|
int ret;
|
|
|
|
|
long timer_id;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Do not start null timer */
|
|
|
|
|
if (sec == 0) {
|
|
|
|
@@ -270,7 +217,6 @@ int nas_timer_start(long sec, nas_timer_callback_t cb, void *args)
|
|
|
|
|
|
|
|
|
|
/* Insert the new entry into the timer queue */
|
|
|
|
|
_nas_timer_db_insert_entry(id, te);
|
|
|
|
|
#if defined(ENABLE_ITTI)
|
|
|
|
|
# if defined(NAS_MME)
|
|
|
|
|
ret = timer_setup(sec, 0, TASK_NAS_MME, INSTANCE_DEFAULT, TIMER_PERIODIC, args, &timer_id);
|
|
|
|
|
# else
|
|
|
|
@@ -280,10 +226,7 @@ int nas_timer_start(long sec, nas_timer_callback_t cb, void *args)
|
|
|
|
|
if (ret == -1) {
|
|
|
|
|
return NAS_TIMER_INACTIVE_ID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
te->timer_id = timer_id;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return (id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -309,11 +252,7 @@ int nas_timer_stop(int id)
|
|
|
|
|
nas_timer_entry_t *entry;
|
|
|
|
|
/* Remove the entry from the timer queue */
|
|
|
|
|
entry = _nas_timer_db_remove_entry(id);
|
|
|
|
|
#if defined(ENABLE_ITTI)
|
|
|
|
|
timer_remove(entry->timer_id);
|
|
|
|
|
#else
|
|
|
|
|
(void)entry;
|
|
|
|
|
#endif
|
|
|
|
|
/* Delete the timer entry */
|
|
|
|
|
_nas_timer_db_delete_entry(id);
|
|
|
|
|
return (NAS_TIMER_INACTIVE_ID);
|
|
|
|
@@ -380,7 +319,7 @@ int nas_timer_restart(int id)
|
|
|
|
|
** Others: _nas_timer_db **
|
|
|
|
|
** **
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
#if defined(ENABLE_ITTI)
|
|
|
|
|
|
|
|
|
|
void nas_timer_handle_signal_expiry(long timer_id, void *arg_p)
|
|
|
|
|
{
|
|
|
|
|
/* Get the timer entry for which the system timer expired */
|
|
|
|
@@ -388,25 +327,7 @@ void nas_timer_handle_signal_expiry(long timer_id, void *arg_p)
|
|
|
|
|
|
|
|
|
|
te->cb(te->args);
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
static void _nas_timer_handler(int signal)
|
|
|
|
|
{
|
|
|
|
|
/* At least one timer has been started */
|
|
|
|
|
assert( (_nas_timer_db.head != NULL) && (_nas_timer_db.head->entry != NULL) );
|
|
|
|
|
|
|
|
|
|
/* Get the timer entry for which the system timer expired */
|
|
|
|
|
nas_timer_entry_t *te = _nas_timer_db.head->entry;
|
|
|
|
|
|
|
|
|
|
threadCreate (&te->pid, te->cb, te->args, "nas-timer", -1, OAI_PRIORITY_RT_LOW);
|
|
|
|
|
|
|
|
|
|
void *result = NULL;
|
|
|
|
|
(void) pthread_join(te->pid, &result);
|
|
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
|
free(result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* -----------------------------------------------------------------------------
|
|
|
|
@@ -605,17 +526,7 @@ static void _nas_timer_db_insert_entry(int id, nas_timer_entry_t *te)
|
|
|
|
|
restart = _nas_timer_db_insert(&_nas_timer_db.tq[id]);
|
|
|
|
|
nas_timer_unlock_db();
|
|
|
|
|
|
|
|
|
|
#if !defined(ENABLE_ITTI)
|
|
|
|
|
|
|
|
|
|
if (restart) {
|
|
|
|
|
/* The new entry is the first entry of the list;
|
|
|
|
|
* restart the system timer */
|
|
|
|
|
setitimer(ITIMER_REAL, &it, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
(void)(restart);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int _nas_timer_db_insert(timer_queue_t *entry)
|
|
|
|
@@ -704,21 +615,8 @@ static nas_timer_entry_t *_nas_timer_db_remove_entry(int id)
|
|
|
|
|
tv.tv_usec = ts.tv_nsec/1000;
|
|
|
|
|
/* tv = tv - time() */
|
|
|
|
|
rc = _nas_timer_sub(&_nas_timer_db.head->entry->tv, &tv, &it.it_value);
|
|
|
|
|
|
|
|
|
|
#if defined(ENABLE_ITTI)
|
|
|
|
|
timer_remove(_nas_timer_db.head->entry->timer_id);
|
|
|
|
|
(void) (rc);
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
if (rc < 0) {
|
|
|
|
|
/* The system timer should have already expired */
|
|
|
|
|
_nas_timer_handler(SIGALRM);
|
|
|
|
|
} else {
|
|
|
|
|
/* Restart the system timer */
|
|
|
|
|
setitimer(ITIMER_REAL, &it, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Return a pointer to the removed entry */
|
|
|
|
@@ -749,17 +647,6 @@ static int _nas_timer_db_remove(timer_queue_t *entry)
|
|
|
|
|
/* Other timers are scheduled to expire */
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if !defined(ENABLE_ITTI)
|
|
|
|
|
{
|
|
|
|
|
/* No more timer is scheduled to expire; stop the system timer */
|
|
|
|
|
struct itimerval it;
|
|
|
|
|
it.it_interval.tv_sec = it.it_interval.tv_usec = 0;
|
|
|
|
|
it.it_value.tv_sec = it.it_value.tv_usec = 0;
|
|
|
|
|
setitimer(ITIMER_REAL, &it, 0);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The entry was NOT the first entry of the list */
|
|
|
|
|