From 89309695626ba47a7e9f4c908a4d46c8b059df0f Mon Sep 17 00:00:00 2001 From: Hanoh Haim Date: Thu, 22 Dec 2016 11:35:11 +0200 Subject: stateful scheduler cleanup Signed-off-by: Hanoh Haim --- src/h_timer.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'src/h_timer.cpp') 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;idetach_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