|
1 | 1 | use super::Absorb;
|
2 | 2 | use crate::read::ReadHandle;
|
3 | 3 |
|
| 4 | +use std::collections::VecDeque; |
4 | 5 | use std::ptr::NonNull;
|
5 | 6 | use std::sync::atomic;
|
6 | 7 | use std::sync::{Arc, MutexGuard};
|
|
24 | 25 | {
|
25 | 26 | epochs: crate::Epochs,
|
26 | 27 | w_handle: NonNull<T>,
|
27 |
| - oplog: Vec<O>, |
| 28 | + oplog: VecDeque<O>, |
28 | 29 | swap_index: usize,
|
29 | 30 | r_handle: ReadHandle<T>,
|
30 | 31 | last_epochs: Vec<usize>,
|
@@ -116,7 +117,7 @@ where
|
116 | 117 | epochs,
|
117 | 118 | // safety: Box<T> is not null and covariant.
|
118 | 119 | w_handle: unsafe { NonNull::new_unchecked(Box::into_raw(Box::new(w_handle))) },
|
119 |
| - oplog: Vec::new(), |
| 120 | + oplog: VecDeque::new(), |
120 | 121 | swap_index: 0,
|
121 | 122 | r_handle,
|
122 | 123 | last_epochs: Vec::new(),
|
@@ -264,14 +265,16 @@ where
|
264 | 265 | /// Returns true if there are operations in the operational log that have not yet been exposed
|
265 | 266 | /// to readers.
|
266 | 267 | pub fn has_pending_operations(&self) -> bool {
|
| 268 | + // NOTE: we don't use self.oplog.is_empty() here because it's not really that important if |
| 269 | + // there are operations that have not yet been applied to the _write_ handle. |
267 | 270 | self.swap_index < self.oplog.len()
|
268 | 271 | }
|
269 | 272 |
|
270 | 273 | /// Append the given operation to the operational log.
|
271 | 274 | ///
|
272 | 275 | /// Its effects will not be exposed to readers until you call [`publish`](Self::publish).
|
273 | 276 | pub fn append(&mut self, op: O) -> &mut Self {
|
274 |
| - self.oplog.push(op); |
| 277 | + self.oplog.push_back(op); |
275 | 278 | self
|
276 | 279 | }
|
277 | 280 |
|
@@ -389,7 +392,7 @@ mod tests {
|
389 | 392 | // pin the epoch
|
390 | 393 | let _count = r.enter();
|
391 | 394 | // refresh would hang here
|
392 |
| - assert!(w.oplog[w.swap_index..].is_empty()); |
| 395 | + assert_eq!(w.oplog.iter().skip(w.swap_index).count(), 0); |
393 | 396 | assert!(!w.has_pending_operations());
|
394 | 397 | }
|
395 | 398 |
|
|
0 commit comments