|
3 | 3 | #include <atomic> |
4 | 4 | #include <cerrno> |
5 | 5 | #include <cstdint> |
| 6 | +#include <cstdlib> |
6 | 7 | #include <vector> |
7 | 8 | #include <string> |
8 | 9 | #include <cmath> |
@@ -315,9 +316,8 @@ static FastDecodeStatus decode_lac_v3_to_mapped_wav(const uint8_t* data, |
315 | 316 |
|
316 | 317 | size_t hardware_threads = |
317 | 318 | std::max<size_t>(1, static_cast<size_t>(std::thread::hardware_concurrency())); |
318 | | - const size_t resolved_limit = LAC::resolve_thread_limit(thread_count); |
319 | | - if (resolved_limit > 0) { |
320 | | - hardware_threads = std::min(hardware_threads, resolved_limit); |
| 319 | + if (thread_count > 0) { |
| 320 | + hardware_threads = std::min(hardware_threads, thread_count); |
321 | 321 | } |
322 | 322 | const size_t worker_count = std::min<size_t>(hardware_threads, block_count); |
323 | 323 |
|
@@ -583,6 +583,13 @@ static bool parse_threads_flag(const std::string& flag, size_t& out_threads) { |
583 | 583 | return true; |
584 | 584 | } |
585 | 585 |
|
| 586 | +static size_t resolve_cli_thread_count(size_t explicit_count) { |
| 587 | + // CLI owns environment resolution: --threads (explicit_count) wins, else |
| 588 | + // LAC_THREADS. The library never reads the environment itself. |
| 589 | + if (explicit_count > 0) return explicit_count; |
| 590 | + return LAC::parse_thread_limit(std::getenv("LAC_THREADS")); |
| 591 | +} |
| 592 | + |
586 | 593 | static void usage() { |
587 | 594 | std::cerr << "Usage:\n"; |
588 | 595 | std::cerr << " lac_cli encode input.wav output.lac [--stereo-mode=lr|ms] [--threads=N] [--debug-threads] [--debug-lpc] [--debug-stereo-est] [--debug-zr] [--debug-partitions] [--no-partitioning]\n"; |
@@ -643,6 +650,7 @@ int main(int argc, char** argv) { |
643 | 650 | return 1; |
644 | 651 | } |
645 | 652 | } |
| 653 | + thread_count = resolve_cli_thread_count(thread_count); |
646 | 654 | std::vector<int32_t> left, right; |
647 | 655 | uint16_t channels = 0; |
648 | 656 | uint32_t sample_rate = 0; |
@@ -725,6 +733,7 @@ int main(int argc, char** argv) { |
725 | 733 | return 1; |
726 | 734 | } |
727 | 735 | } |
| 736 | + thread_count = resolve_cli_thread_count(thread_count); |
728 | 737 | std::vector<uint8_t> bitstream; |
729 | 738 | if (!load_file(in_path, bitstream)) { |
730 | 739 | std::cerr << "Failed to read LAC file: " << in_path << "\n"; |
|
0 commit comments