Skip to content

Commit a8b902f

Browse files
alexandruagandreeaflorescu
authored andcommitted
add AtomicBitmap::get_and_reset
Signed-off-by: Alexandru Agache <[email protected]>
1 parent 40d70d7 commit a8b902f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/bitmap/backend/atomic_bitmap.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ impl AtomicBitmap {
8484
self.size
8585
}
8686

87+
/// Atomically get and reset the dirty page bitmap.
88+
pub fn get_and_reset(&self) -> Vec<u64> {
89+
self.map
90+
.iter()
91+
.map(|u| u.fetch_and(0, Ordering::SeqCst))
92+
.collect()
93+
}
94+
8795
/// Reset all bitmap bits to 0.
8896
pub fn reset(&self) {
8997
for it in self.map.iter() {
@@ -193,6 +201,16 @@ mod tests {
193201
assert!(!b.is_addr_set(128));
194202
assert!(!b.is_addr_set(256));
195203
assert!(!b.is_addr_set(384));
204+
205+
b.set_addr_range(128, 129);
206+
let v = b.get_and_reset();
207+
208+
assert!(!b.is_addr_set(128));
209+
assert!(!b.is_addr_set(256));
210+
assert!(!b.is_addr_set(384));
211+
212+
assert_eq!(v.len(), 1);
213+
assert_eq!(v[0], 0b110);
196214
}
197215

198216
#[test]

0 commit comments

Comments
 (0)