mirror of
https://github.com/Hizenberg469/WheelTimer.git
synced 2026-04-19 18:52:22 +03:00
made posix timer as embedded timer instead of 'has a' timer within
wrapper timer
This commit is contained in:
59
WheelTimer/libtimer/Course/timerlib.h
Normal file
59
WheelTimer/libtimer/Course/timerlib.h
Normal 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__ */
|
||||||
@@ -151,8 +151,6 @@ delete_timer(Timer_t *timer){
|
|||||||
int rc;
|
int rc;
|
||||||
rc = timer_delete(*(timer->posix_timer));
|
rc = timer_delete(*(timer->posix_timer));
|
||||||
assert(rc >= 0);
|
assert(rc >= 0);
|
||||||
free(timer->posix_timer);
|
|
||||||
timer->posix_timer = NULL;
|
|
||||||
timer->user_arg = NULL; /* User arg need to be freed by Appln */
|
timer->user_arg = NULL; /* User arg need to be freed by Appln */
|
||||||
timer_set_state(timer, TIMER_DELETED);
|
timer_set_state(timer, TIMER_DELETED);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user