summaryrefslogtreecommitdiffstats
path: root/src/h_timer.h
diff options
context:
space:
mode:
authorHanoh Haim <hhaim@cisco.com>2016-12-22 11:35:11 +0200
committerHanoh Haim <hhaim@cisco.com>2016-12-22 17:32:14 +0200
commit89309695626ba47a7e9f4c908a4d46c8b059df0f (patch)
treee316c2ec05d42558dde0c0a7d43c864bb91c1ad7 /src/h_timer.h
parent7b8e05fc8996827a99d5da74b30138a15c89a96e (diff)
stateful scheduler cleanup
Signed-off-by: Hanoh Haim <hhaim@cisco.com>
Diffstat (limited to 'src/h_timer.h')
-rw-r--r--src/h_timer.h68
1 files changed, 64 insertions, 4 deletions
diff --git a/src/h_timer.h b/src/h_timer.h
index 1d57640b..a937d548 100644
--- a/src/h_timer.h
+++ b/src/h_timer.h
@@ -40,9 +40,64 @@ typedef enum {
} RC_HTW_t;
+class CHTimerWheelErrorStr {
+public:
+ CHTimerWheelErrorStr(RC_HTW_t val){
+ m_err=val;
+ }
+ const char * get_str(void){
+ switch (m_err) {
+ case RC_HTW_OK:
+ return ("RC_HTW_OK");
+ break;
+ case RC_HTW_ERR_NO_RESOURCES :
+ return ("RC_HTW_ERR_NO_RESOURCES");
+ break;
+ case RC_HTW_ERR_TIMER_IS_ON :
+ return ("RC_HTW_ERR_TIMER_IS_ON");
+ break;
+ case RC_HTW_ERR_NO_LOG2 :
+ return ("RC_HTW_ERR_NO_LOG2");
+ break;
+ case RC_HTW_ERR_MAX_WHEELS :
+ return ("RC_HTW_ERR_MAX_WHEELS");
+ break;
+ case RC_HTW_ERR_NOT_ENOUGH_BITS :
+ return ("RC_HTW_ERR_NOT_ENOUGH_BITS");
+ break;
+ default:
+ assert(0);
+ }
+ }
+ const char * get_help_str(void){
+ switch (m_err) {
+ case RC_HTW_OK:
+ return ("ok");
+ break;
+ case RC_HTW_ERR_NO_RESOURCES :
+ return ("not enough memory");
+ break;
+ case RC_HTW_ERR_TIMER_IS_ON :
+ return ("timer is already on, you should stop before start");
+ break;
+ case RC_HTW_ERR_NO_LOG2 :
+ return ("number of buckets should be log2");
+ break;
+ case RC_HTW_ERR_MAX_WHEELS :
+ return ("maximum number of wheels is limited to 4");
+ break;
+ case RC_HTW_ERR_NOT_ENOUGH_BITS :
+ return ("(log2(buckets) * number of wheels) should be less than 32, try to reduce the number of wheels");
+ break;
+ default:
+ assert(0);
+ }
+ }
-
+private:
+ RC_HTW_t m_err;
+};
class CHTimerWheelLink {
@@ -76,7 +131,7 @@ public:
}
void detach(void){
- #ifdef HTW_DEBUG
+ #ifdef _DEBUG
assert(m_next);
#endif
CHTimerWheelLink *next;
@@ -134,7 +189,7 @@ public:
inline RC_HTW_t timer_start(CHTimerObj *tmr,
htw_ticks_t ticks){
- #ifdef HTW_DEBUG
+ #ifdef _DEBUG
if ( tmr->is_running() ){
return( RC_HTW_ERR_TIMER_IS_ON);
}
@@ -146,6 +201,8 @@ public:
RC_HTW_t timer_stop (CHTimerObj *tmr);
+ uint32_t detach_all(void *userdata,htw_on_tick_cb_t cb);
+
inline bool check_timer_tick_cycle(){
return (m_tick_done);
}
@@ -247,6 +304,7 @@ public:
RC_HTW_t Delete();
+
inline RC_HTW_t timer_start(CHTimerObj *tmr,
htw_ticks_t ticks){
m_total_events++;
@@ -265,7 +323,9 @@ public:
bool is_any_events_left(){
return(m_total_events>0?true:false);
}
-
+
+ /* iterate all, detach and call the callback */
+ void detach_all(void *userdata,htw_on_tick_cb_t cb);
private: