diff options
author | Garrett D'Amore <garrett@damore.org> | 2016-04-18 16:32:35 -0700 |
---|---|---|
committer | Garrett D'Amore <garrett@damore.org> | 2016-04-19 16:10:24 -0700 |
commit | 4b88a3b68ed1bdd4c57ba80e2a52b31a4846831f (patch) | |
tree | 217fe80a3c4e3b9a9dd9da3e73dc1cd6decb0859 /src/aio | |
parent | afc358657e75fd7ec11fe083ea2e6bcc59a64bb2 (diff) | |
download | nanomsg-4b88a3b68ed1bdd4c57ba80e2a52b31a4846831f.tar.gz |
fixes #640 clock_rdtsc is unsafe
Diffstat (limited to 'src/aio')
-rw-r--r-- | src/aio/timerset.c | 9 | ||||
-rw-r--r-- | src/aio/timerset.h | 4 |
2 files changed, 6 insertions, 7 deletions
diff --git a/src/aio/timerset.c b/src/aio/timerset.c index 9f7384e..dac23ea 100644 --- a/src/aio/timerset.c +++ b/src/aio/timerset.c @@ -24,18 +24,17 @@ #include "../utils/fast.h" #include "../utils/cont.h" +#include "../utils/clock.h" #include "../utils/err.h" void nn_timerset_init (struct nn_timerset *self) { - nn_clock_init (&self->clock); nn_list_init (&self->timeouts); } void nn_timerset_term (struct nn_timerset *self) { nn_list_term (&self->timeouts); - nn_clock_term (&self->clock); } int nn_timerset_add (struct nn_timerset *self, int timeout, @@ -46,7 +45,7 @@ int nn_timerset_add (struct nn_timerset *self, int timeout, int first; /* Compute the instant when the timeout will be due. */ - hndl->timeout = nn_clock_now (&self->clock) + timeout; + hndl->timeout = nn_clock_ms() + timeout; /* Insert it into the ordered list of timeouts. */ for (it = nn_list_begin (&self->timeouts); @@ -87,7 +86,7 @@ int nn_timerset_timeout (struct nn_timerset *self) return -1; timeout = (int) (nn_cont (nn_list_begin (&self->timeouts), - struct nn_timerset_hndl, list)->timeout - nn_clock_now (&self->clock)); + struct nn_timerset_hndl, list)->timeout - nn_clock_ms()); return timeout < 0 ? 0 : timeout; } @@ -102,7 +101,7 @@ int nn_timerset_event (struct nn_timerset *self, struct nn_timerset_hndl **hndl) /* If no timeout have expired yet, there's no event to return. */ first = nn_cont (nn_list_begin (&self->timeouts), struct nn_timerset_hndl, list); - if (first->timeout > nn_clock_now (&self->clock)) + if (first->timeout > nn_clock_ms()) return -EAGAIN; /* Return the first timeout and remove it from the list of active diff --git a/src/aio/timerset.h b/src/aio/timerset.h index 3e4dc1e..d3ec5c1 100644 --- a/src/aio/timerset.h +++ b/src/aio/timerset.h @@ -23,7 +23,8 @@ #ifndef NN_TIMERSET_INCLUDED #define NN_TIMERSET_INCLUDED -#include "../utils/clock.h" +#include <stdint.h> + #include "../utils/list.h" /* This class stores a list of timeouts and reports the next one to expire @@ -35,7 +36,6 @@ struct nn_timerset_hndl { }; struct nn_timerset { - struct nn_clock clock; struct nn_list timeouts; }; |