From c83b337c7a63bfe10bb06f4f02c456c42883749d Mon Sep 17 00:00:00 2001 From: monica Date: Wed, 22 Mar 2023 13:58:45 -0400 Subject: [PATCH] added comments --- zssp/src/fragged.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/zssp/src/fragged.rs b/zssp/src/fragged.rs index e4174e247..286a548f0 100644 --- a/zssp/src/fragged.rs +++ b/zssp/src/fragged.rs @@ -58,6 +58,7 @@ impl Fragged { #[inline(always)] pub fn assemble(&self, counter: u64, fragment: Fragment, fragment_no: u8, fragment_count: u8) -> Option> { if fragment_no < fragment_count && (fragment_count as usize) <= MAX_FRAGMENTS { + // We must hold the RwLock for the entire duration of this function, in case the counter changes and we need to drop everything let r = self.counter_want.read().unwrap(); let (mut r_counter, mut r_want) = *r; let mut _r_guard = Some(r); @@ -65,6 +66,7 @@ impl Fragged { // If the counter has changed, reset the structure to receive a new packet. if counter != r_counter { + // Switch to locking in write mode, and recheck the condition in case another thread entered the critical section while relocking. _r_guard.take(); let mut w = self.counter_want.write().unwrap(); let (w_counter, w_want) = *w;