Skip to content

Commit d14b25e

Browse files
authored
Merge pull request #7 from Bathtor/timer-ref-clone
Ensure that TimerRef is always Clone
2 parents f1907d8 + c937082 commit d14b25e

File tree

7 files changed

+41
-22
lines changed

7 files changed

+41
-22
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
uses: actions-rs/toolchain@v1
6363
with:
6464
profile: minimal
65-
toolchain: nightly-2023-02-11
65+
toolchain: nightly-2024-09-25
6666
override: true
6767
components: rustfmt, clippy
6868
- name: Checkout sources
@@ -91,7 +91,7 @@ jobs:
9191
uses: actions-rs/toolchain@v1
9292
with:
9393
profile: minimal
94-
toolchain: nightly-2023-02-11
94+
toolchain: nightly-2024-09-25
9595
override: true
9696
components: rustfmt, clippy
9797
- name: Checkout sources

Cargo.toml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[package]
22
name = "hierarchical_hash_wheel_timer"
3-
version = "1.2.0"
3+
version = "1.3.0"
44
authors = ["Lars Kroll <[email protected]>"]
5-
edition = "2018"
5+
edition = "2021"
66
description = "A low-level timer implementantion using a hierarchical four-level hash wheel with overflow."
77
documentation = "https://docs.rs/hierarchical_hash_wheel_timer"
88
homepage = "https://github.com/Bathtor/rust-hash-wheel-timer"
@@ -26,23 +26,23 @@ fnv-hash = ["fnv"]
2626
fx-hash = ["rustc-hash"]
2727

2828
[dependencies]
29-
uuid = { version = "1.3", features = ["v4"] , optional = true}
30-
fnv = { version = "1.0", optional = true}
31-
rustc-hash = {version = "1.1", optional = true}
32-
crossbeam-channel = {version = "0.5", optional = true}
29+
uuid = { version = "1.3", features = ["v4"], optional = true }
30+
fnv = { version = "1.0", optional = true }
31+
rustc-hash = { version = "2", optional = true }
32+
crossbeam-channel = { version = "0.5", optional = true }
3333

3434
[badges]
3535
# Maintenance: `status` is required Available options are `actively-developed`,
3636
# `passively-maintained`, `as-is`, `none`, `experimental`, `looking-for-maintainer`
3737
# and `deprecated`.
3838
maintenance = { status = "passively-maintained" }
3939

40-
travis-ci = { repository = "Bathtor/rust-hash-wheel-timer", branch = "master" }
40+
github-actions = { repository = "Bathtor/rust-hash-wheel-timer", workflow = "ci.yml" }
4141

4242
[dev-dependencies]
43-
criterion = "0.3"
44-
rand = "0.7"
45-
rand_xoshiro = "0.4"
43+
criterion = "0.5"
44+
rand = "0.8"
45+
rand_xoshiro = "0.6"
4646

4747
[[bench]]
4848
name = "wheel_benchmark"

rustfmt.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ empty_item_single_line = true
1313
struct_lit_single_line = true
1414
fn_single_line = false
1515
where_single_line = false
16-
imports_granularity="Crate"
16+
imports_granularity = "Crate"
1717
imports_indent = "Block"
1818
imports_layout = "HorizontalVertical"
1919
reorder_imports = true
@@ -43,11 +43,11 @@ use_field_init_shorthand = false
4343
force_explicit_abi = true
4444
condense_wildcard_suffixes = false
4545
color = "Auto"
46-
required_version = "1.5.2"
46+
required_version = "1.8.0"
4747
unstable_features = false
4848
disable_all_formatting = false
4949
skip_children = false
50-
hide_parse_errors = false
50+
show_parse_errors = true
5151
error_on_line_overflow = false
5252
error_on_unformatted = false
5353
ignore = []

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
//!
2828
//! - The [quad_wheel::QuadWheelWithOverflow](wheels::quad_wheel::QuadWheelWithOverflow) corresponds directly to the implementation described above.
2929
//! - The [cancellable::QuadWheelWithOverflow](wheels::cancellable::QuadWheelWithOverflow) additionally supports the cancellation of outstanding timers
30-
//! before they expire. In order to do so, however, it requires the generic timer entry type to provide a unique identifier field. It also uses
31-
//! [Rc](std::rc::Rc) internally to avoid double storing the actual entry, which makes it (potentialy) unsuitable for situations where the timer must
32-
//! be able to move threads (since Rc](std::rc::Rc) is not `Send`).
30+
//! before they expire. In order to do so, however, it requires the generic timer entry type to provide a unique identifier field. It also uses
31+
//! [Rc](std::rc::Rc) internally to avoid double storing the actual entry, which makes it (potentialy) unsuitable for situations where the timer must
32+
//! be able to move threads (since Rc](std::rc::Rc) is not `Send`).
3333
//!
3434
//! # 3 – High Level APIs
3535
//! This crate also provides two high levels APIs that can either be used directly or can be seen as examples

src/thread_timer.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ where
6565
/// This is used to schedule events on the timer from other threads.
6666
///
6767
/// You can get an instance via [timer_ref](TimerWithThread::timer_ref).
68-
#[derive(Clone)]
6968
pub struct TimerRef<I, O, P>
7069
where
7170
I: Hash + Clone + Eq,
@@ -109,7 +108,18 @@ where
109108
.unwrap_or_else(|e| eprintln!("Could not send Cancel msg: {:?}", e));
110109
}
111110
}
112-
111+
impl<I, O, P> Clone for TimerRef<I, O, P>
112+
where
113+
I: Hash + Clone + Eq,
114+
O: OneshotState<Id = I>,
115+
P: PeriodicState<Id = I>,
116+
{
117+
fn clone(&self) -> Self {
118+
Self {
119+
work_queue: self.work_queue.clone(),
120+
}
121+
}
122+
}
113123
/// A timer implementation that uses its own thread
114124
///
115125
/// This struct acts as a main handle for the timer and its thread.
@@ -563,4 +573,14 @@ mod tests {
563573
assert!(*guard);
564574
}
565575
}
576+
577+
/// Check that the TimeRef is cloneable, even if its type parameters aren't.
578+
#[test]
579+
fn timer_ref_clone() {
580+
let timer = TimerWithThread::for_uuid_closures();
581+
let timer_ref: TimerRef<Uuid, OneShotClosureState<Uuid>, PeriodicClosureState<Uuid>> =
582+
timer.timer_ref();
583+
// No need to use it. Just checking that it compiles.
584+
let _cloned_ref = timer_ref.clone();
585+
}
566586
}

src/wheels/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use std::{
99
mem,
1010
rc::{Rc, Weak},
1111
time::Duration,
12-
u32,
1312
};
1413

1514
pub mod byte_wheel;

src/wheels/quad_wheel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ where
166166
self.secondary.current(),
167167
self.primary.current(),
168168
];
169-
u32::from_be(unsafe { mem::transmute(time_bytes) })
169+
u32::from_be_bytes(time_bytes)
170170
}
171171

172172
/// Insert a new timeout into the wheel to be returned after `delay` ticks

0 commit comments

Comments
 (0)