summaryrefslogtreecommitdiffstats
path: root/src/h_timer.cpp
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.cpp
parent7b8e05fc8996827a99d5da74b30138a15c89a96e (diff)
stateful scheduler cleanup
Signed-off-by: Hanoh Haim <hhaim@cisco.com>
Diffstat (limited to 'src/h_timer.cpp')
-rw-r--r--src/h_timer.cpp44
1 files changed, 42 insertions, 2 deletions
diff --git a/src/h_timer.cpp b/src/h_timer.cpp
index baaaca31..b3d86d46 100644
--- a/src/h_timer.cpp
+++ b/src/h_timer.cpp
@@ -27,6 +27,10 @@ void CHTimerObj::Dump(FILE *fd){
}
+
+void detach_all(void *userdata,htw_on_tick_cb_t cb);
+
+
RC_HTW_t CHTimerOneWheel::Create(uint32_t wheel_size){
CHTimerWheelLink *bucket;
@@ -67,6 +71,26 @@ RC_HTW_t CHTimerOneWheel::Delete(){
}
+
+uint32_t CHTimerOneWheel::detach_all(void *userdata,htw_on_tick_cb_t cb){
+
+ uint32_t m_total_events=0;
+ int i;
+ for (i = 0; i < m_wheel_size; i++) {
+ CHTimerWheelLink * lp=&m_buckets[i];
+ CHTimerWheelLink * first;
+
+ while (!lp->is_self()) {
+ first = lp->m_next;
+ first->detach();
+ m_total_events++;
+ assert(cb);
+ cb(userdata,(CHTimerObj *)first);
+ }
+ }
+ return (m_total_events);
+}
+
RC_HTW_t CHTimerOneWheel::timer_stop(CHTimerObj *tmr){
if ( tmr->is_running() ) {
tmr->detach();
@@ -107,11 +131,27 @@ void CHTimerOneWheel::dump_link_list(uint32_t bucket_index,
}
-void CHTimerWheel::on_tick(void *userdata,htw_on_tick_cb_t cb){
-
+void CHTimerWheel::detach_all(void *userdata,htw_on_tick_cb_t cb){
+ #ifndef _DEBUG
+ if (m_total_events==0) {
+ return;
+ }
+ #endif
int i;
+ uint32_t res=0;
+ for (i=0;i<m_num_wheels; i++) {
+ CHTimerOneWheel * lp=&m_timer_w[i];
+ res=lp->detach_all(userdata,cb);
+ assert(m_total_events>=res);
+ m_total_events -=res;
+ }
+ assert(m_total_events==0);
+}
+void CHTimerWheel::on_tick(void *userdata,htw_on_tick_cb_t cb){
+
+ int i;
for (i=0;i<m_num_wheels; i++) {
CHTimerOneWheel * lp=&m_timer_w[i];
CHTimerObj * event;