| 118 | // ---------------------------------------------------------------------------------------- |
| 119 | |
| 120 | void timer_global_clock:: |
| 121 | adjust_delay ( |
| 122 | timer_base* r, |
| 123 | unsigned long new_delay |
| 124 | ) |
| 125 | { |
| 126 | if (r->in_global_clock) |
| 127 | { |
| 128 | remove(r); |
| 129 | // compute the new next_time_to_run and store it in t |
| 130 | uint64 t = r->next_time_to_run; |
| 131 | t -= r->delay*1000; |
| 132 | t += new_delay*1000; |
| 133 | |
| 134 | tm.reset(); |
| 135 | if (!tm.move_next() || t < tm.element().key()) |
| 136 | { |
| 137 | // we need to make the thread adjust its next time to |
| 138 | // trigger if this new event occurrs sooner than the |
| 139 | // next event in tm |
| 140 | s.signal(); |
| 141 | } |
| 142 | |
| 143 | // set this incase add throws |
| 144 | r->running = false; |
| 145 | r->delay = new_delay; |
| 146 | |
| 147 | timer_base* rtemp = r; |
| 148 | uint64 ttemp = t; |
| 149 | tm.add(ttemp,rtemp); |
| 150 | r->next_time_to_run = t; |
| 151 | r->in_global_clock = true; |
| 152 | |
| 153 | // put this back now that we know add didn't throw |
| 154 | r->running = true; |
| 155 | |
| 156 | } |
| 157 | else |
| 158 | { |
| 159 | r->delay = new_delay; |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | // ---------------------------------------------------------------------------------------- |
| 164 | |