#include <cstdio>
#include <cstring>
+#include <thread>
namespace pzstd {
numThreads = parseUnsigned(argv[i]);
if (numThreads == 0) {
std::fprintf(stderr, "Invalid argument: # of threads must be > 0.\n");
+ return false;
}
break;
case 'p':
if (compressionLevel > maxCLevel) {
std::fprintf(
stderr, "Invalid compression level %u.\n", compressionLevel);
+ return false;
}
}
// Check that numThreads is set
if (numThreads == 0) {
- std::fprintf(stderr, "Invalid arguments: # of threads not specified.\n");
- return false;
+ numThreads = std::thread::hardware_concurrency();
+ if (numThreads == 0) {
+ std::fprintf(stderr, "Invalid arguments: # of threads not specified "
+ "and unable to determine hardware concurrency.\n");
+ return false;
+ }
}
return true;
}
}
}
-TEST(Options, BadNumThreads) {
+TEST(Options, NumThreads) {
{
Options options;
std::array<const char*, 3> args = {{nullptr, "-o", "-"}};
- EXPECT_FALSE(options.parse(args.size(), args.data()));
+ EXPECT_TRUE(options.parse(args.size(), args.data()));
}
{
Options options;