job/queue: avoid noexcept termination in default_parallelism

This commit is contained in:
Danny Robson 2019-04-15 10:35:49 +10:00
parent f4ef1dc9a0
commit 39107bb62c

View File

@ -3,13 +3,14 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
* *
* Copyright 2018 Danny Robson <danny@nerdcruft.net> * Copyright 2018-2019 Danny Robson <danny@nerdcruft.net>
*/ */
#include "queue.hpp" #include "queue.hpp"
#include "../parse/value.hpp" #include "../parse/value.hpp"
#include "../scoped.hpp" #include "../scoped.hpp"
#include "../log.hpp"
using cruft::job::queue; using cruft::job::queue;
@ -18,8 +19,12 @@ using cruft::job::queue;
unsigned unsigned
queue::default_parallelism (void) noexcept queue::default_parallelism (void) noexcept
{ {
if (auto var = getenv ("JOB_THREADS")) { try {
return cruft::parse::from_string<unsigned> (var); if (auto var = getenv ("JOB_THREADS")) {
return cruft::parse::from_string<unsigned> (var);
}
} catch (...) {
LOG_ERROR ("Unable to parse JOB_THREADS. Using the default");
} }
return std::thread::hardware_concurrency (); return std::thread::hardware_concurrency ();