0001-use-std-time-bump-to-0.5.4.patch 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. From 6aa867bc4e6df72fbab4f6968b7ffa7d3b6e11f6 Mon Sep 17 00:00:00 2001
  2. From: Oussama <md.oussama@gmail.com>
  3. Date: Thu, 4 Jan 2018 14:53:22 +0100
  4. Subject: [PATCH] use std::time & bump to 0.5.4
  5. Submitted upstream at <https://github.com/csherratt/pulse/pull/1>
  6. ---
  7. Cargo.toml | 3 +--
  8. src/lib.rs | 14 +++++++-------
  9. 2 files changed, 8 insertions(+), 9 deletions(-)
  10. diff --git a/Cargo.toml b/Cargo.toml
  11. index 70b1e92..816f4c9 100644
  12. --- a/Cargo.toml
  13. +++ b/Cargo.toml
  14. @@ -1,6 +1,6 @@
  15. [package]
  16. name = "pulse"
  17. -version = "0.5.3"
  18. +version = "0.5.4"
  19. authors = ["Colin Sherratt <colin.sherratt@gmail.com>"]
  20. license = "Apache-2.0"
  21. description = "A library for async wake signals"
  22. @@ -8,7 +8,6 @@ homepage = "https://github.com/csherratt/pulse"
  23. [dependencies]
  24. atom = "0.3"
  25. -time = "0.1"
  26. [features]
  27. default = []
  28. diff --git a/src/lib.rs b/src/lib.rs
  29. index f874e76..b5a72d5 100644
  30. --- a/src/lib.rs
  31. +++ b/src/lib.rs
  32. @@ -13,7 +13,6 @@
  33. // limitations under the License.
  34. extern crate atom;
  35. -extern crate time;
  36. use std::sync::atomic::AtomicUsize;
  37. use std::thread;
  38. @@ -24,9 +23,10 @@ use std::sync::atomic::Ordering;
  39. use std::cell::RefCell;
  40. use atom::*;
  41. -use time::precise_time_s;
  42. use fnbox::FnBox;
  43. +use std::time::{Duration,Instant};
  44. +
  45. pub use select::{Select, SelectMap};
  46. pub use barrier::Barrier;
  47. mod select;
  48. @@ -517,17 +517,17 @@ impl Scheduler for ThreadScheduler {
  49. }
  50. fn wait_timeout_ms(&self, signal: Signal, ms: u32) -> Result<(), TimeoutError> {
  51. - let mut now = (precise_time_s() * 1000.) as u64;
  52. - let end = now + ms as u64;
  53. + let now = Instant::now();
  54. + let total = Duration::from_millis(ms as _);
  55. loop {
  56. let id = signal.add_to_waitlist(Waiting::thread());
  57. if signal.is_pending() {
  58. - now = (precise_time_s() * 1000.) as u64;
  59. - if now > end {
  60. + let elapsed = now.elapsed();
  61. + if elapsed > total {
  62. return Err(TimeoutError::Timeout);
  63. }
  64. - thread::park_timeout_ms((end - now) as u32);
  65. + thread::park_timeout(total - elapsed);
  66. }
  67. signal.remove_from_waitlist(id);
  68. --
  69. 2.36.0