Skip to content

Commit d619162

Browse files
committed
Minimize lock region
1 parent 26a4e57 commit d619162

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

Diff for: src/task_cleanup.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -318,29 +318,29 @@ async fn task_cleanup_impl(
318318
}
319319
};
320320

321-
let matched = actual_cache_size + active_downloading_size == *mg_cache_size;
321+
let cache_size = *mg_cache_size;
322+
let difference = cache_size.abs_diff(actual_cache_size + active_downloading_size);
322323

323-
if matched {
324+
/* auto-repair small abnormalities */
325+
if difference < 10 * 1024 {
326+
*mg_cache_size = actual_cache_size + active_downloading_size;
327+
}
328+
329+
drop(mg_cache_size);
330+
331+
if difference == 0 {
324332
debug!(
325333
"actual cache size: {}; stored cache size: {}; active download size: {}",
326-
actual_cache_size, *mg_cache_size, active_downloading_size,
334+
actual_cache_size, cache_size, active_downloading_size,
327335
);
328336
} else {
329337
// TODO: check for inconsistencies and repair
330338

331-
let difference = (*mg_cache_size).abs_diff(actual_cache_size + active_downloading_size);
332339
warn!(
333340
"actual cache size: {}; stored cache size: {}; active download size: {}; size difference: {}",
334-
actual_cache_size, *mg_cache_size, active_downloading_size, difference,
341+
actual_cache_size, cache_size, active_downloading_size, difference,
335342
);
336-
337-
/* auto-repair small abnormalities */
338-
if difference < 10 * 1024 {
339-
*mg_cache_size = actual_cache_size + active_downloading_size;
340-
}
341343
}
342-
343-
drop(mg_cache_size);
344344
}
345345

346346
info!(

0 commit comments

Comments
 (0)