|
7 | 7 | // Licensed under the Apache License, Version 2.0 (the "License"); |
8 | 8 | // you may not use this file except in compliance with the License. |
9 | 9 | // You may obtain a copy of the License at |
10 | | -// |
| 10 | +// |
11 | 11 | // http://www.apache.org/licenses/LICENSE-2.0 |
12 | | -// |
| 12 | +// |
13 | 13 | // Unless required by applicable law or agreed to in writing, software |
14 | 14 | // distributed under the License is distributed on an "AS IS" BASIS, |
15 | 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
28 | 28 | class Timers |
29 | 29 | { |
30 | 30 | public: |
31 | | - using id_t = uint32_t; |
| 31 | + using id_t = int32_t; |
32 | 32 | using duration_t = std::chrono::microseconds; |
33 | 33 | using handler_t = delegate<void(id_t)>; |
34 | | - |
| 34 | + |
| 35 | + static constexpr id_t UNUSED_ID = -1; |
| 36 | + |
35 | 37 | /// create a one-shot timer that triggers @when from now |
36 | 38 | /// returns a timer id |
37 | 39 | static id_t oneshot(duration_t when, const handler_t&); |
38 | 40 | /// create a periodic timer that begins @when and repeats every @period |
39 | 41 | static id_t periodic(duration_t when, duration_t period, const handler_t&); |
40 | 42 | // un-schedule timer, and free it |
41 | 43 | static void stop(id_t); |
42 | | - |
| 44 | + |
43 | 45 | /// returns the number of current, active timers |
44 | 46 | static size_t active(); |
45 | | - |
| 47 | + |
46 | 48 | /// initialization |
47 | 49 | typedef delegate<void(duration_t)> start_func_t; |
48 | 50 | typedef delegate<void()> stop_func_t; |
49 | 51 | static void init(const start_func_t&, const stop_func_t&); |
50 | 52 | /// signal from the underlying hardware that it is calibrated and ready to go |
51 | 53 | static void ready(); |
52 | | - |
| 54 | + |
53 | 55 | /// handler that processes timer interrupts |
54 | 56 | static void timers_handler(); |
55 | 57 | }; |
|
0 commit comments