| 61 | // ---------------------------------------------------------------------------------------- |
| 62 | |
| 63 | void timer_global_clock:: |
| 64 | add ( |
| 65 | timer_base* r |
| 66 | ) |
| 67 | { |
| 68 | if (r->in_global_clock == false) |
| 69 | { |
| 70 | // if the thread isn't running then start it up |
| 71 | if (!running) |
| 72 | { |
| 73 | start(); |
| 74 | running = true; |
| 75 | } |
| 76 | |
| 77 | uint64 t = ts.get_timestamp() + r->delay*1000; |
| 78 | tm.reset(); |
| 79 | if (!tm.move_next() || t < tm.element().key()) |
| 80 | { |
| 81 | // we need to make the thread adjust its next time to |
| 82 | // trigger if this new event occurrs sooner than the |
| 83 | // next event in tm |
| 84 | s.signal(); |
| 85 | } |
| 86 | timer_base* rtemp = r; |
| 87 | uint64 ttemp = t; |
| 88 | tm.add(ttemp,rtemp); |
| 89 | r->next_time_to_run = t; |
| 90 | r->in_global_clock = true; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | // ---------------------------------------------------------------------------------------- |
| 95 | |