diff options
author | Andy Finch <andyfinch7@gmail.com> | 2020-02-09 13:54:16 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-09 10:54:16 -0800 |
commit | 1abd408770f6dc4205a471bb79d48b643f53074d (patch) | |
tree | b0d3c0e40932e7885158b65aee33db7968c80db2 /core/shared_queue.rs | |
parent | 61c5bb86db42a2d575f51e966dbc77f711c64054 (diff) |
No longer require aligned buffer for shared queue (#3935)
Fixes: #3925
Diffstat (limited to 'core/shared_queue.rs')
-rw-r--r-- | core/shared_queue.rs | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/core/shared_queue.rs b/core/shared_queue.rs index d69284404..dad3e380d 100644 --- a/core/shared_queue.rs +++ b/core/shared_queue.rs @@ -181,7 +181,6 @@ impl SharedQueue { end, record.len() ); - assert_eq!(record.len() % 4, 0); let index = self.num_records(); if end > self.bytes().len() || index >= MAX_RECORDS { debug!("WARNING the sharedQueue overflowed"); @@ -259,21 +258,21 @@ mod tests { #[test] fn overflow() { let mut q = SharedQueue::new(RECOMMENDED_SIZE); - assert!(q.push(0, &alloc_buf(RECOMMENDED_SIZE - 4))); + assert!(q.push(0, &alloc_buf(RECOMMENDED_SIZE - 1))); assert_eq!(q.size(), 1); - assert!(!q.push(0, &alloc_buf(8))); + assert!(!q.push(0, &alloc_buf(2))); assert_eq!(q.size(), 1); - assert!(q.push(0, &alloc_buf(4))); + assert!(q.push(0, &alloc_buf(1))); assert_eq!(q.size(), 2); let (_op_id, buf) = q.shift().unwrap(); - assert_eq!(buf.len(), RECOMMENDED_SIZE - 4); + assert_eq!(buf.len(), RECOMMENDED_SIZE - 1); assert_eq!(q.size(), 1); - assert!(!q.push(0, &alloc_buf(4))); + assert!(!q.push(0, &alloc_buf(1))); let (_op_id, buf) = q.shift().unwrap(); - assert_eq!(buf.len(), 4); + assert_eq!(buf.len(), 1); assert_eq!(q.size(), 0); } @@ -281,19 +280,25 @@ mod tests { fn full_records() { let mut q = SharedQueue::new(RECOMMENDED_SIZE); for _ in 0..MAX_RECORDS { - assert!(q.push(0, &alloc_buf(4))) + assert!(q.push(0, &alloc_buf(1))) } - assert_eq!(q.push(0, &alloc_buf(4)), false); + assert_eq!(q.push(0, &alloc_buf(1)), false); // Even if we shift one off, we still cannot push a new record. let _ignored = q.shift().unwrap(); - assert_eq!(q.push(0, &alloc_buf(4)), false); + assert_eq!(q.push(0, &alloc_buf(1)), false); } #[test] - #[should_panic] - fn bad_buf_length() { + fn allow_any_buf_length() { let mut q = SharedQueue::new(RECOMMENDED_SIZE); // check that `record` that has length not a multiple of 4 will cause panic + q.push(0, &alloc_buf(1)); + q.push(0, &alloc_buf(2)); q.push(0, &alloc_buf(3)); + q.push(0, &alloc_buf(4)); + q.push(0, &alloc_buf(5)); + q.push(0, &alloc_buf(6)); + q.push(0, &alloc_buf(7)); + q.push(0, &alloc_buf(8)); } } |