suffix_set(optarg);
break;
- case 'T':
+ case 'T': {
+ // Since xz 5.4.0: Ignore leading '+' first.
+ const char *s = optarg;
+ if (optarg[0] == '+')
+ ++s;
+
// The max is from src/liblzma/common/common.h.
- hardware_threads_set(str_to_uint64("threads",
- optarg, 0, 16384));
+ uint32_t t = str_to_uint64("threads", s, 0, 16384);
+
+ // If leading '+' was used then use multi-threaded
+ // mode even if exactly one thread was specified.
+ if (t == 1 && optarg[0] == '+')
+ t = UINT32_MAX;
+
+ hardware_threads_set(t);
break;
+ }
// --version
case 'V':
/// on the available hardware threads.
static bool threads_are_automatic = false;
+/// If true, then try to use multi-threaded mode (if memlimit allows)
+/// even if only one thread was requested explicitly (-T+1).
+static bool use_mt_mode_with_one_thread = false;
+
/// Memory usage limit for compression
static uint64_t memlimit_compress = 0;
extern void
hardware_threads_set(uint32_t n)
{
+ // Reset these to false first and set them to true when appropriate.
+ threads_are_automatic = false;
+ use_mt_mode_with_one_thread = false;
+
if (n == 0) {
// Automatic number of threads was requested.
+ // If there is only one hardware thread, multi-threaded
+ // mode will still be used if memory limit allows.
threads_are_automatic = true;
+ use_mt_mode_with_one_thread = true;
// If threading support was enabled at build time,
// use the number of available CPU cores. Otherwise
#else
threads_max = 1;
#endif
+ } else if (n == UINT32_MAX) {
+ use_mt_mode_with_one_thread = true;
+ threads_max = 1;
} else {
threads_max = n;
- threads_are_automatic = false;
}
return;
hardware_threads_is_mt(void)
{
#ifdef MYTHREAD_ENABLED
- return threads_max > 1 || threads_are_automatic;
+ return threads_max > 1 || use_mt_mode_with_one_thread;
#else
return false;
#endif
/// Set the maximum number of worker threads.
+/// A special value of UINT32_MAX sets one thread in multi-threaded mode.
extern void hardware_threads_set(uint32_t threadlimit);
/// Get the maximum number of worker threads.
.\" This file has been put into the public domain.
.\" You can do whatever you want with this file.
.\"
-.TH XZ 1 "2022-11-09" "Tukaani" "XZ Utils"
+.TH XZ 1 "2022-11-19" "Tukaani" "XZ Utils"
.
.SH NAME
xz, unxz, xzcat, lzma, unlzma, lzcat \- Compress or decompress .xz and .lzma files
5.2.x
used single-threaded mode in this situation.)
.IP ""
+To use multi-threaded mode with only one thread, set
+.I threads
+to
+.BR +1 .
+The
+.B +
+prefix has no effect with values other than
+.BR 1 .
+A memory usage limit can still make
+.B xz
+switch to single-threaded mode unless
+.B \-\-no\-adjust
+is used.
+Support for the
+.B +
+prefix was added in
+.B xz
+5.4.0.
+.IP ""
If an automatic number of threads has been requested and
no memory usage limit has been specified,
then a system-specific default soft limit will be used to possibly