Skip to content

Commit 1aa6697

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 7077f20 commit 1aa6697

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

dumbo/src/tcp/connection.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,16 @@ pub enum WriteNextError {
113113

114114
// This generates pseudo random u32 numbers based on the current timestamp. Only works for x86_64,
115115
// but can find something else if we ever need to support different architectures.
116-
#[cfg(target_arch = "x86_64")]
117116
fn xor_rng_u32() -> u32 {
118-
// Safe because there's nothing that can go wrong with this call.
119-
let mut t = unsafe { std::arch::x86_64::_rdtsc() } as u32;
120-
117+
let mut t: u32 = {
118+
#[cfg(target_arch = "x86_64")]
119+
// Safe because there's nothing that can go wrong with this call.
120+
unsafe {
121+
std::arch::x86_64::_rdtsc() as u32
122+
}
123+
#[cfg(not(target_arch = "x86_64"))]
124+
0
125+
};
121126
// Taken from https://en.wikipedia.org/wiki/Xorshift
122127
t ^= t << 13;
123128
t ^= t >> 17;
@@ -1786,4 +1791,11 @@ pub(crate) mod tests {
17861791
// and we don't wait for our FIN to be ACKed.
17871792
assert!(c.is_done());
17881793
}
1794+
1795+
#[test]
1796+
fn test_xor_rng_u32() {
1797+
for _ in 0..1000 {
1798+
assert_ne!(xor_rng_u32(), xor_rng_u32());
1799+
}
1800+
}
17891801
}

0 commit comments

Comments
 (0)