| 152 | } |
| 153 | |
| 154 | static void insert_active_timer(uc_engine *uc, struct Timer *tim) { |
| 155 | struct TimerState* timers = &uc->fw->timers; |
| 156 | struct Timer *cursor = timers->active_head; |
| 157 | int64_t ticker_val; |
| 158 | |
| 159 | // Reset intermediate elapsed time |
| 160 | sync_timers(uc); |
| 161 | |
| 162 | if(!cursor) { |
| 163 | // First entry |
| 164 | timers->active_head = tim; |
| 165 | timers->cur_countdown = tim->ticker_val; |
| 166 | uc->set_timer_countdown(uc->ctx, uc->fw->timers.cur_countdown); |
| 167 | timers->cur_interval = tim->ticker_val; |
| 168 | } else if ((ticker_val = tim->ticker_val) <= cursor->ticker_val) { |
| 169 | // New first entry |
| 170 | tim->next = cursor; |
| 171 | timers->active_head = tim; |
| 172 | timers->cur_countdown = tim->ticker_val; |
| 173 | uc->set_timer_countdown(uc->ctx, uc->fw->timers.cur_countdown); |
| 174 | timers->cur_interval = tim->ticker_val; |
| 175 | } else { |
| 176 | // Find the entry after which to insert the timer |
| 177 | for(;cursor->next && (ticker_val > cursor->next->ticker_val); cursor = cursor->next); |
| 178 | tim->next = cursor->next; |
| 179 | cursor->next = tim; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | static inline void remove_active_timer(uc_engine *uc, struct Timer *tim) { |
| 184 | struct TimerState* timers = &uc->fw->timers; |
no test coverage detected