aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/eloop_win.c
diff options
context:
space:
mode:
authorJohannes Berg <johannes.berg@intel.com>2013-11-20 10:01:09 (GMT)
committerJouni Malinen <j@w1.fi>2013-11-20 21:52:56 (GMT)
commit594516b4c28a94ca686b17f1e463dfd6712b75a7 (patch)
tree35ea1f20347d6f31dd7836ef1dbaa42948303445 /src/utils/eloop_win.c
parent461e3ebe434872f840ca43cf86da014af14f9de9 (diff)
downloadhostap-594516b4c28a94ca686b17f1e463dfd6712b75a7.zip
hostap-594516b4c28a94ca686b17f1e463dfd6712b75a7.tar.gz
hostap-594516b4c28a94ca686b17f1e463dfd6712b75a7.tar.bz2
Use monotonic clock for relative time for eloop if available
Relative time shouldn't be calculated based on gettimeofday because that clock can jump (e.g., when the time is adjusted by the system administrator.) On systems where that is available, use CLOCK_BOOTTIME (on fairly recent Linux systems, this clock takes into account the time spend suspended) or CLOCK_MONOTONIC (on Linux and some POSIX systems, this clock is just freely running with no adjustments.) Reported-by: Holger Schurig <holgerschurig@gmail.com> Signed-hostap: Johannes Berg <johannes.berg@intel.com>
Diffstat (limited to 'src/utils/eloop_win.c')
-rw-r--r--src/utils/eloop_win.c44
1 files changed, 22 insertions, 22 deletions
diff --git a/src/utils/eloop_win.c b/src/utils/eloop_win.c
index e87d82a..a1f9996 100644
--- a/src/utils/eloop_win.c
+++ b/src/utils/eloop_win.c
@@ -31,7 +31,7 @@ struct eloop_event {
struct eloop_timeout {
struct dl_list list;
- struct os_time time;
+ struct os_reltime time;
void *eloop_data;
void *user_data;
eloop_timeout_handler handler;
@@ -244,7 +244,7 @@ int eloop_register_timeout(unsigned int secs, unsigned int usecs,
timeout = os_zalloc(sizeof(*timeout));
if (timeout == NULL)
return -1;
- if (os_get_time(&timeout->time) < 0) {
+ if (os_get_reltime(&timeout->time) < 0) {
os_free(timeout);
return -1;
}
@@ -271,7 +271,7 @@ int eloop_register_timeout(unsigned int secs, unsigned int usecs,
/* Maintain timeouts in order of increasing time */
dl_list_for_each(tmp, &eloop.timeout, struct eloop_timeout, list) {
- if (os_time_before(&timeout->time, &tmp->time)) {
+ if (os_reltime_before(&timeout->time, &tmp->time)) {
dl_list_add(tmp->list.prev, &timeout->list);
return 0;
}
@@ -313,13 +313,13 @@ int eloop_cancel_timeout(eloop_timeout_handler handler,
int eloop_cancel_timeout_one(eloop_timeout_handler handler,
void *eloop_data, void *user_data,
- struct os_time *remaining)
+ struct os_reltime *remaining)
{
struct eloop_timeout *timeout, *prev;
int removed = 0;
- struct os_time now;
+ struct os_reltime now;
- os_get_time(&now);
+ os_get_reltime(&now);
remaining->sec = remaining->usec = 0;
dl_list_for_each_safe(timeout, prev, &eloop.timeout,
@@ -328,8 +328,8 @@ int eloop_cancel_timeout_one(eloop_timeout_handler handler,
(timeout->eloop_data == eloop_data) &&
(timeout->user_data == user_data)) {
removed = 1;
- if (os_time_before(&now, &timeout->time))
- os_time_sub(&timeout->time, &now, remaining);
+ if (os_reltime_before(&now, &timeout->time))
+ os_reltime_sub(&timeout->time, &now, remaining);
eloop_remove_timeout(timeout);
break;
}
@@ -358,7 +358,7 @@ int eloop_deplete_timeout(unsigned int req_secs, unsigned int req_usecs,
eloop_timeout_handler handler, void *eloop_data,
void *user_data)
{
- struct os_time now, requested, remaining;
+ struct os_reltime now, requested, remaining;
struct eloop_timeout *tmp;
dl_list_for_each(tmp, &eloop.timeout, struct eloop_timeout, list) {
@@ -367,9 +367,9 @@ int eloop_deplete_timeout(unsigned int req_secs, unsigned int req_usecs,
tmp->user_data == user_data) {
requested.sec = req_secs;
requested.usec = req_usecs;
- os_get_time(&now);
- os_time_sub(&tmp->time, &now, &remaining);
- if (os_time_before(&requested, &remaining)) {
+ os_get_reltime(&now);
+ os_reltime_sub(&tmp->time, &now, &remaining);
+ if (os_reltime_before(&requested, &remaining)) {
eloop_cancel_timeout(handler, eloop_data,
user_data);
eloop_register_timeout(requested.sec,
@@ -389,7 +389,7 @@ int eloop_replenish_timeout(unsigned int req_secs, unsigned int req_usecs,
eloop_timeout_handler handler, void *eloop_data,
void *user_data)
{
- struct os_time now, requested, remaining;
+ struct os_reltime now, requested, remaining;
struct eloop_timeout *tmp;
dl_list_for_each(tmp, &eloop.timeout, struct eloop_timeout, list) {
@@ -398,9 +398,9 @@ int eloop_replenish_timeout(unsigned int req_secs, unsigned int req_usecs,
tmp->user_data == user_data) {
requested.sec = req_secs;
requested.usec = req_usecs;
- os_get_time(&now);
- os_time_sub(&tmp->time, &now, &remaining);
- if (os_time_before(&remaining, &requested)) {
+ os_get_reltime(&now);
+ os_reltime_sub(&tmp->time, &now, &remaining);
+ if (os_reltime_before(&remaining, &requested)) {
eloop_cancel_timeout(handler, eloop_data,
user_data);
eloop_register_timeout(requested.sec,
@@ -530,7 +530,7 @@ int eloop_register_signal_reconfig(eloop_signal_handler handler,
void eloop_run(void)
{
- struct os_time tv, now;
+ struct os_reltime tv, now;
DWORD count, ret, timeout_val, err;
size_t i;
@@ -542,9 +542,9 @@ void eloop_run(void)
timeout = dl_list_first(&eloop.timeout, struct eloop_timeout,
list);
if (timeout) {
- os_get_time(&now);
- if (os_time_before(&now, &timeout->time))
- os_time_sub(&timeout->time, &now, &tv);
+ os_get_reltime(&now);
+ if (os_reltime_before(&now, &timeout->time))
+ os_reltime_sub(&timeout->time, &now, &tv);
}
count = 0;
@@ -583,8 +583,8 @@ void eloop_run(void)
timeout = dl_list_first(&eloop.timeout, struct eloop_timeout,
list);
if (timeout) {
- os_get_time(&now);
- if (!os_time_before(&now, &timeout->time)) {
+ os_get_reltime(&now);
+ if (!os_reltime_before(&now, &timeout->time)) {
void *eloop_data = timeout->eloop_data;
void *user_data = timeout->user_data;
eloop_timeout_handler handler =