You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.2 KiB
72 lines
2.2 KiB
5 months ago
|
From 64a98f1bdc2a37c4dd1f29ee6886ed5f4688439e Mon Sep 17 00:00:00 2001
|
||
|
From: Daniel Reiter Horn <danielrh@users.sourceforge.net>
|
||
|
Date: Wed, 2 Oct 2024 00:43:00 -0700
|
||
|
Subject: [PATCH] Fix 32 bit tests by allocating less memory by running with
|
||
|
less parallelism in that case
|
||
|
|
||
|
---
|
||
|
src/enc/test.rs | 33 ++++++++++++++++++++++++++++++++-
|
||
|
1 file changed, 32 insertions(+), 1 deletion(-)
|
||
|
|
||
|
diff --git a/src/enc/test.rs b/src/enc/test.rs
|
||
|
index 744472b..854d9b8 100755
|
||
|
--- a/src/enc/test.rs
|
||
|
+++ b/src/enc/test.rs
|
||
|
@@ -211,6 +211,34 @@ fn oneshot_compress(
|
||
|
|
||
|
(true, next_out_offset)
|
||
|
}
|
||
|
+static lock32: core::sync::atomic::AtomicU32 = core::sync::atomic::AtomicU32::new(0);
|
||
|
+
|
||
|
+/// 32bit systems do not have sufficient memory to compress multiple items
|
||
|
+/// at the same time with the current limits and defaults. So we instead spin
|
||
|
+/// until a process has completed compression. We cannot use proper locks
|
||
|
+/// in nostd, so we fall back to this simple spin lock.
|
||
|
+#[cfg(target_pointer_width = "32")]
|
||
|
+fn lock_if_32bit(){
|
||
|
+ use core::sync::atomic::Ordering;
|
||
|
+ loop {
|
||
|
+ let cur = lock32.fetch_add(1, Ordering::SeqCst);
|
||
|
+ if cur == 0 {
|
||
|
+ return;
|
||
|
+ }
|
||
|
+ lock32.fetch_sub(1, Ordering::SeqCst);
|
||
|
+ }
|
||
|
+}
|
||
|
+#[cfg(target_pointer_width = "32")]
|
||
|
+fn unlock_if_32bit(){
|
||
|
+ use core::sync::atomic::Ordering;
|
||
|
+ lock32.fetch_sub(1, Ordering::SeqCst);
|
||
|
+}
|
||
|
+#[cfg(not(target_pointer_width = "32"))]
|
||
|
+fn lock_if_32bit(){
|
||
|
+}
|
||
|
+#[cfg(not(target_pointer_width = "32"))]
|
||
|
+fn unlock_if_32bit(){
|
||
|
+}
|
||
|
|
||
|
fn oneshot_decompress(compressed: &[u8], output: &mut [u8]) -> (BrotliResult, usize, usize) {
|
||
|
let mut available_in: usize = compressed.len();
|
||
|
@@ -255,6 +283,7 @@ fn oneshot(
|
||
|
in_buffer_size: usize,
|
||
|
out_buffer_size: usize,
|
||
|
) -> (BrotliResult, usize, usize) {
|
||
|
+ lock_if_32bit();
|
||
|
let (success, mut available_in) = oneshot_compress(
|
||
|
input,
|
||
|
compressed,
|
||
|
@@ -268,7 +297,9 @@ fn oneshot(
|
||
|
//return (BrotliResult::ResultFailure, 0, 0);
|
||
|
available_in = compressed.len();
|
||
|
}
|
||
|
- oneshot_decompress(&mut compressed[..available_in], output)
|
||
|
+ let ret = oneshot_decompress(&mut compressed[..available_in], output);
|
||
|
+ unlock_if_32bit();
|
||
|
+ ret
|
||
|
}
|
||
|
|
||
|
#[test]
|
||
|
--
|
||
|
2.46.1
|
||
|
|