diff options
| author | Emil Fresk <emil.fresk@gmail.com> | 2020-12-13 14:20:28 +0100 |
|---|---|---|
| committer | Emil Fresk <emil.fresk@gmail.com> | 2020-12-13 14:20:28 +0100 |
| commit | 0e134a41b5f53843b5e1c90cd0633ae56b7a3113 (patch) | |
| tree | 0830a142ff340480e3cfd660578422184be2847f | |
| parent | dd52539e32690c5cff73efe40c5d443b770d82a0 (diff) | |
Double check the compare instant
| -rw-r--r-- | src/tq.rs | 17 |
1 files changed, 13 insertions, 4 deletions
@@ -84,13 +84,22 @@ where Some(_) => { // TODO: Fix this hack... // Extract the compare time - let new_instant = *instant.duration_since_epoch().integer(); - M::set_compare(new_instant); + M::set_compare(*instant.duration_since_epoch().integer()); + + // Double check that the instant we set is really in the future, else + // dequeue. If the monotonic is fast enough it can happen that from the + // read of now to the set of the compare, the time can overflow. This is to + // guard against this. + if instant.checked_duration_since(&M::now()).is_none() { + let nr = self.0.pop_unchecked(); + + Some((nr.task, nr.index)) + } else { + None + } // Start counting down from the new reload // mem::transmute::<_, SYST>(()).clear_current(); - - None } } } else { |
