made posix timer as embedded timer instead of 'has a' timer within

wrapper timer
This commit is contained in:
Abhishek Sagar
2020-10-23 23:09:05 -07:00
parent c7d25ba6f9
commit 4f0bc181b6
2 changed files with 59 additions and 2 deletions

View File

@@ -0,0 +1,59 @@
/*
* =====================================================================================
*
* Filename: timerlib.h
*
* Description: This file is a wrapper over Timer POSIX Timer library
*
* Version: 1.0
* Created: 10/12/2020 01:47:16 PM
* Revision: none
* Compiler: gcc
*
* Author: ABHISHEK SAGAR (), sachinites@gmail.com
* Organization: Juniper Networks
*
* =====================================================================================
*/
#ifndef __TIMER_WRAP__
#define __TIMER_WRAP__
#include <signal.h>
#include <time.h>
#include <unistd.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
typedef enum{
TIMER_INIT,
TIMER_DELETED,
TIMER_PAUSED,
TIMER_CANCELLED,
TIMER_RESUMED,
TIMER_RUNNING,
} TIMER_STATE_T;
typedef struct Timer_{
/* Timer config */
timer_t posix_timer;
void *user_arg;
unsigned long exp_timer; /* in milli-sec */
unsigned long sec_exp_timer; /* in milli-sec */
uint32_t thresdhold; /* No of times to invoke the timer callback */
void (*cb)(struct Timer_ *, void *); /* Timer Callback */
bool exponential_backoff;
/* place holder value to store
* dynamic attributes of timer */
unsigned long time_remaining; /* Time left for paused timer for next expiration */
uint32_t invocation_counter;
struct itimerspec ts;
unsigned long exp_back_off_time;
TIMER_STATE_T timer_state;
} Timer_t;
#endif /* __TIMER_WRAP__ */

View File

@@ -151,8 +151,6 @@ delete_timer(Timer_t *timer){
int rc;
rc = timer_delete(*(timer->posix_timer));
assert(rc >= 0);
free(timer->posix_timer);
timer->posix_timer = NULL;
timer->user_arg = NULL; /* User arg need to be freed by Appln */
timer_set_state(timer, TIMER_DELETED);
}