diff --git a/include/WheelTimer.h b/include/WheelTimer.h new file mode 100644 index 0000000..4ff6d82 --- /dev/null +++ b/include/WheelTimer.h @@ -0,0 +1,20 @@ +#ifndef __WHEEL_TIMER_H +#define __WHEEL_TIMER_H + +#include + +typdedef struct _wheel_timer_t { + + int current_clock_tic; /*Pointer to current slot, pointed by clock tic*/ + int clock_tic_interval; /*Time interval of each clock tick*/ + int wheel_size; /*No. of slots in wheel timer*/ + int current_cycle_no; /*No. of rotation completed by wheel timer clock tic*/ + pthread_t wheel_thread; /*Thread where the wheel timer clock run separately*/ + /*@@@@@@@@@@@@*/ + ll_t* slots[0]; /*Array of linked list, where each index in array represent a slot*/ + /*@@@@@@@@@@@@*/ + +} wheel_timer_t; + + +#endif \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 521f184..abec4c0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,13 +1,12 @@ #timerlib.c src file... set(TIMER_LIB_SRC "timerlib.c") +set(WHEEL_TIMER_LIB_SRC "WheelTimer.c") #Library add_library(${TIMER_LIB} STATIC - ${TIMER_LIB_SRC}) + ${TIMER_LIB_SRC} + ${WHEEL_TIMER_LIB_SRC}) -#Including Header file dir... -target_include_directories(${TIMER_LIB} PUBLIC - ${HEADER_DIR}) #Linking dependent library... @@ -17,7 +16,15 @@ if( NOT (CMAKE_SYSTEM_NAME STREQUAL "Linux") ) endif() set(POSIX_TIMER_LIB rt) +set(THREADS_PREFER_PTHREAD_FLAG ON) +find_package(Threads REQUIRED) target_link_libraries(${TIMER_LIB} PUBLIC - ${POSIX_TIMER_LIB}) \ No newline at end of file + ${POSIX_TIMER_LIB} + Threads::Threads) + + +#Including Header file dir... +target_include_directories(${TIMER_LIB} PUBLIC + ${HEADER_DIR}) \ No newline at end of file diff --git a/src/WheelTimer.c b/src/WheelTimer.c new file mode 100644 index 0000000..e69de29 diff --git a/src/timerlib.c b/src/timerlib.c index 47a54c8..5680033 100644 --- a/src/timerlib.c +++ b/src/timerlib.c @@ -48,12 +48,6 @@ timer_callback_wrapper(union sigval arg) { return; } - if (timer->timer_state == TIMER_RESUMED) { - if (timer->sec_exp_time != 0) { - timer->timer_state = TIMER_RUNNING; - } - } - (timer->cb)(timer, timer->user_arg); if (timer->exponential_backoff) { @@ -157,6 +151,7 @@ delete_timer(Timer_t* timer) { timer_set_state(timer, TIMER_DELETED); free(timer->posix_timer); free(timer); + timer = NULL; } void