| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include "utils/s2n_timer.h" |
| 17 |
|
| 18 |
#include "tls/s2n_config.h" |
| 19 |
#include "utils/s2n_result.h" |
| 20 |
#include "utils/s2n_safety.h" |
| 21 |
|
| 22 |
S2N_RESULT s2n_timer_start(struct s2n_config *config, struct s2n_timer *timer) |
| 23 |
{ |
| 24 |
RESULT_ENSURE(config->monotonic_clock(config->monotonic_clock_ctx, &timer->time) >= S2N_SUCCESS, |
| 25 |
S2N_ERR_CANCELLED); |
| 26 |
|
| 27 |
return S2N_RESULT_OK; |
| 28 |
} |
| 29 |
|
| 30 |
S2N_RESULT s2n_timer_elapsed(struct s2n_config *config, struct s2n_timer *timer, uint64_t *nanoseconds) |
| 31 |
{ |
| 32 |
uint64_t current_time = 0; |
| 33 |
|
| 34 |
RESULT_ENSURE(config->monotonic_clock(config->monotonic_clock_ctx, ¤t_time) >= S2N_SUCCESS, |
| 35 |
S2N_ERR_CANCELLED); |
| 36 |
|
| 37 |
*nanoseconds = current_time - timer->time; |
| 38 |
|
| 39 |
return S2N_RESULT_OK; |
| 40 |
} |
| 41 |
|
| 42 |
S2N_RESULT s2n_timer_reset(struct s2n_config *config, struct s2n_timer *timer, uint64_t *nanoseconds) |
| 43 |
{ |
| 44 |
uint64_t previous_time = timer->time; |
| 45 |
|
| 46 |
RESULT_GUARD(s2n_timer_start(config, timer)); |
| 47 |
|
| 48 |
*nanoseconds = timer->time - previous_time; |
| 49 |
|
| 50 |
return S2N_RESULT_OK; |
| 51 |
} |