Skip to content

Commit

Permalink
Fix aftrer rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
bwoebi committed Aug 16, 2024
1 parent 5105c9a commit e776ee0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
1 change: 1 addition & 0 deletions ddcommon/src/rate_limiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ fn now() -> u64 {

let mut perf_counter = 0;
windows_sys::Win32::System::Performance::QueryPerformanceCounter(&mut perf_counter);
perf_counter as u64 * frequency / TIME_PER_SECOND as u64
};
#[cfg(not(windows))]
let now = {
Expand Down
7 changes: 7 additions & 0 deletions ipc/src/rate_limiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ mod tests {
use crate::rate_limiter::{ShmLimiterData, ShmLimiterMemory};
use ddcommon::rate_limiter::Limiter;
use std::ffi::CString;
use std::thread::sleep;
use std::time::Duration;

fn path() -> CString {
CString::new("/ddlimiters-test".to_string()).unwrap()
Expand All @@ -227,9 +229,14 @@ mod tests {
let limiter_idx = limiter.idx;
// Two are allowed, then one more because a small amount of time passed since the first one
assert!(limiter.inc(2));
// Add a minimal amount of time to ensure the test doesn't run faster than timer precision
sleep(Duration::from_micros(100));
assert!(limiter.inc(2));
sleep(Duration::from_micros(100));
assert!(limiter.inc(2));
sleep(Duration::from_micros(100));
assert!(!limiter.inc(2));
sleep(Duration::from_micros(100));
assert!(!limiter.inc(2));

// Now test the free list
Expand Down
12 changes: 0 additions & 12 deletions sidecar/src/one_way_shared_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,6 @@ impl<T: FileBackedHandle + From<MappedMem<T>>> OneWayShmWriter<T> {
}
}

pub fn as_slice(&self) -> &[u8] {
let handle = self.handle.lock().unwrap();
let mapped = handle.as_ref().unwrap();
let data = unsafe { &*(mapped.as_slice() as *const [u8] as *const RawData) };
if data.meta.size > 0 {
let slice = data.as_slice();
&slice[..slice.len() - 1] // ignore the trailing zero
} else {
b""
}
}

pub fn size(&self) -> usize {
self.handle.lock().unwrap().as_slice().len()
}
Expand Down

0 comments on commit e776ee0

Please sign in to comment.