Skip to content

Commit 971708f

Browse files
committed
dumbo: correctly label x86_64 specific function
On other architectures, make this function return a dummy value. Also, added unit test for the x86_64 scenarios. Signed-off-by: Diana Popa <[email protected]>
1 parent 4115fd6 commit 971708f

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

dumbo/src/tcp/connection.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,16 @@ pub enum WriteNextError {
7373

7474
// This generates pseudo random u32 numbers based on the current timestamp. Only works for x86_64,
7575
// but can find something else if we ever need to support different architectures.
76-
#[cfg(target_arch = "x86_64")]
7776
fn xor_rng_u32() -> u32 {
78-
// Safe because there's nothing that can go wrong with this call.
79-
let mut t = unsafe { std::arch::x86_64::_rdtsc() } as u32;
80-
77+
let mut t: u32 = {
78+
#[cfg(target_arch = "x86_64")]
79+
// Safe because there's nothing that can go wrong with this call.
80+
unsafe {
81+
std::arch::x86_64::_rdtsc() as u32
82+
}
83+
#[cfg(not(target_arch = "x86_64"))]
84+
0
85+
};
8186
// Taken from https://en.wikipedia.org/wiki/Xorshift
8287
t ^= t << 13;
8388
t ^= t >> 17;
@@ -1651,4 +1656,11 @@ pub(crate) mod tests {
16511656
// and we don't wait for our FIN to be ACKed.
16521657
assert!(c.is_done());
16531658
}
1659+
1660+
#[test]
1661+
fn test_xor_rng_u32() {
1662+
for _ in 0..1000 {
1663+
assert_ne!(xor_rng_u32(), xor_rng_u32());
1664+
}
1665+
}
16541666
}

0 commit comments

Comments
 (0)