mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-20 00:55:43 +00:00
OpenEXR limit: only a refusal for size depends on the limit's generation; sequentially consistent counters (#3749 review)
This commit is contained in:
1 parent
bdf500f4ba
commit
a7e7cb6b6a
2 files changed
+15
-9
No files matched your search
@@ -529,7 +529,9 @@ impl PlaneStore {
|
||||
}
|
||||
// (a failure of the file as it was before: the file changed since, it is read again)
|
||||
let limit = effectcraft_render::memory::decode_limit_generation();
|
||||
if let Some((_, _, why, _)) = e.failed.iter().find(|(of, failed, _, made_at)| Arc::ptr_eq(of, index) && *made_at == limit && asks_at_least(index, want, failed)) {
|
||||
if let Some((_, _, why, _)) = e.failed.iter().find(|(of, failed, refusal, made_at)| {
|
||||
Arc::ptr_eq(of, index) && (!matches!(refusal, Refused::TooLarge(_)) || *made_at == limit) && asks_at_least(index, want, failed)
|
||||
}) {
|
||||
return Step::Done(Err(why.clone()));
|
||||
}
|
||||
if let Some(flight) = e.flight.clone() {
|
||||
@@ -678,7 +680,9 @@ impl PlaneStore {
|
||||
(fs.index.clone(), fs.want.clone())
|
||||
};
|
||||
// (failures of another version of the file no longer apply)
|
||||
e.failed.retain(|(of, _, _, made_at)| Arc::ptr_eq(of, &index) && *made_at == flight.limit_generation);
|
||||
// (a refusal for the size counts under the limit it was made under only)
|
||||
e.failed
|
||||
.retain(|(of, _, old, made_at)| Arc::ptr_eq(of, &index) && (!matches!(old, Refused::TooLarge(_)) || *made_at == flight.limit_generation));
|
||||
if e.failed.len() >= FAILED_KEPT {
|
||||
e.failed.remove(0);
|
||||
}
|
||||
|
||||
@@ -440,8 +440,10 @@ static DECODE_ASKING: Mutex<()> = Mutex::new(());
|
||||
const DECODE_ASKS: usize = 2;
|
||||
|
||||
fn store_decode_limit(bytes: usize) {
|
||||
if DECODE_LIMIT.swap(bytes, Ordering::Relaxed) != bytes {
|
||||
DECODE_GENERATION.fetch_add(1, Ordering::Relaxed);
|
||||
// (the limit before its generation, both sequentially consistent: whoever sees the new
|
||||
// generation sees the new limit)
|
||||
if DECODE_LIMIT.swap(bytes, Ordering::SeqCst) != bytes {
|
||||
DECODE_GENERATION.fetch_add(1, Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -456,7 +458,7 @@ pub fn set_decode_limit(bytes: Option<usize>) {
|
||||
/// Changes whenever [`decode_limit`] gives another answer: a request refused for its size is
|
||||
/// asked again after that.
|
||||
pub fn decode_limit_generation() -> u64 {
|
||||
DECODE_GENERATION.load(Ordering::Relaxed)
|
||||
DECODE_GENERATION.load(Ordering::SeqCst)
|
||||
}
|
||||
|
||||
/// Where [`decode_limit`] reads the limit from while nothing set it: the CLI and the MCP server
|
||||
@@ -475,10 +477,10 @@ pub fn decode_limit(floor: usize, need: usize) -> usize {
|
||||
if need <= floor || cfg!(target_arch = "wasm32") {
|
||||
return floor;
|
||||
}
|
||||
if DECODE_LIMIT.load(Ordering::Relaxed) == 0 && DECODE_UNANSWERED.load(Ordering::Relaxed) < DECODE_ASKS {
|
||||
if DECODE_LIMIT.load(Ordering::SeqCst) == 0 {
|
||||
let _asking = DECODE_ASKING.lock().unwrap_or_else(PoisonError::into_inner);
|
||||
// (another thread may have just read it)
|
||||
if DECODE_LIMIT.load(Ordering::Relaxed) == 0 {
|
||||
// (another thread may have just read it, or have used up the asks)
|
||||
if DECODE_LIMIT.load(Ordering::SeqCst) == 0 && DECODE_UNANSWERED.load(Ordering::Relaxed) < DECODE_ASKS {
|
||||
let source = *DECODE_SOURCE.lock().unwrap_or_else(PoisonError::into_inner);
|
||||
match source.and_then(|read| read()) {
|
||||
Some(bytes) => store_decode_limit(bytes),
|
||||
@@ -488,7 +490,7 @@ pub fn decode_limit(floor: usize, need: usize) -> usize {
|
||||
}
|
||||
}
|
||||
}
|
||||
floor.max(DECODE_LIMIT.load(Ordering::Relaxed))
|
||||
floor.max(DECODE_LIMIT.load(Ordering::SeqCst))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in new issue
Block a user