aboutsummaryrefslogtreecommitdiff
path: root/src/xz/hardware.c
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2022-04-14 12:59:09 +0300
committerLasse Collin <lasse.collin@tukaani.org>2022-04-14 13:00:40 +0300
commit0adc13bfe32c14f3e4c6ce9f2d4fdf4112ab53f4 (patch)
tree3be604a3828ab11f6286340bec3df3a5ddbe946a /src/xz/hardware.c
parentxz: Changes to --memlimit-compress and --no-adjust. (diff)
downloadxz-0adc13bfe32c14f3e4c6ce9f2d4fdf4112ab53f4.tar.xz
xz: Make -T0 use multithreaded mode on single-core systems.
The main problem withi the old behavior is that the compressed output is different on single-core systems vs. multicore systems. This commit fixes it by making -T0 one thread in multithreaded mode on single-core systems. The downside of this is that it uses more memory. However, if --memlimit-compress is used, xz can (thanks to the previous commit) drop to the single-threaded mode still.
Diffstat (limited to 'src/xz/hardware.c')
-rw-r--r--src/xz/hardware.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/xz/hardware.c b/src/xz/hardware.c
index d45d6ade..18eee7ec 100644
--- a/src/xz/hardware.c
+++ b/src/xz/hardware.c
@@ -17,6 +17,10 @@
/// the --threads=NUM command line option.
static uint32_t threads_max = 1;
+/// True when the number of threads is automatically determined based
+/// on the available hardware threads.
+static bool threads_are_automatic = false;
+
/// Memory usage limit for compression
static uint64_t memlimit_compress = 0;
@@ -48,6 +52,8 @@ hardware_threads_set(uint32_t n)
{
if (n == 0) {
// Automatic number of threads was requested.
+ threads_are_automatic = true;
+
// If threading support was enabled at build time,
// use the number of available CPU cores. Otherwise
// use one thread since disabling threading support
@@ -61,6 +67,7 @@ hardware_threads_set(uint32_t n)
#endif
} else {
threads_max = n;
+ threads_are_automatic = false;
}
return;
@@ -74,6 +81,13 @@ hardware_threads_get(void)
}
+extern bool
+hardware_threads_is_mt(void)
+{
+ return threads_max > 1 || threads_are_automatic;
+}
+
+
extern void
hardware_memlimit_set(uint64_t new_memlimit,
bool set_compress, bool set_decompress, bool set_mtdec,