about summary refs log tree commit diff
path: root/third_party/nix/src/libutil/thread-pool.cc
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-05-19T17·55+0100
committerVincent Ambo <tazjin@google.com>2020-05-19T17·55+0100
commit867055133d3f487e52dd44149f76347c2c28bf10 (patch)
treec367803ad94f024b0052727a2c7a037af169169a /third_party/nix/src/libutil/thread-pool.cc
parentc6a31838cd7e88ebcb01422b329a499d04ab4b6b (diff)
style(3p/nix): Add braces around single-line conditionals r/771
These were not caught by the previous clang-tidy invocation, but were
instead sorted out using amber[0] as such:

    ambr --regex 'if (\(.+\))\s([a-z].*;)' 'if $1 { $2 }'

[0]: https://github.com/dalance/amber
Diffstat (limited to 'third_party/nix/src/libutil/thread-pool.cc')
-rw-r--r--third_party/nix/src/libutil/thread-pool.cc24
1 files changed, 18 insertions, 6 deletions
diff --git a/third_party/nix/src/libutil/thread-pool.cc b/third_party/nix/src/libutil/thread-pool.cc
index ee727aacd0..a16f4c2b60 100644
--- a/third_party/nix/src/libutil/thread-pool.cc
+++ b/third_party/nix/src/libutil/thread-pool.cc
@@ -10,7 +10,9 @@ ThreadPool::ThreadPool(size_t _maxThreads) : maxThreads(_maxThreads) {
 
   if (!maxThreads) {
     maxThreads = std::thread::hardware_concurrency();
-    if (!maxThreads) maxThreads = 1;
+    if (!maxThreads) {
+      maxThreads = 1;
+    }
   }
 
   DLOG(INFO) << "starting pool of " << maxThreads - 1 << " threads";
@@ -26,7 +28,9 @@ void ThreadPool::shutdown() {
     std::swap(workers, state->workers);
   }
 
-  if (workers.empty()) return;
+  if (workers.empty()) {
+    return;
+  }
 
   DLOG(INFO) << "reaping " << workers.size() << " worker threads";
 
@@ -62,7 +66,9 @@ void ThreadPool::process() {
 
     assert(quit);
 
-    if (state->exception) std::rethrow_exception(state->exception);
+    if (state->exception) {
+      std::rethrow_exception(state->exception);
+    }
 
   } catch (...) {
     /* In the exceptional case, some workers may still be
@@ -76,7 +82,9 @@ void ThreadPool::process() {
 }
 
 void ThreadPool::doWork(bool mainThread) {
-  if (!mainThread) interruptCheck = [&]() { return (bool)quit; };
+  if (!mainThread) {
+    interruptCheck = [&]() { return (bool)quit; };
+  }
 
   bool didWork = false;
   std::exception_ptr exc;
@@ -114,9 +122,13 @@ void ThreadPool::doWork(bool mainThread) {
       /* Wait until a work item is available or we're asked to
          quit. */
       while (true) {
-        if (quit) return;
+        if (quit) {
+          return;
+        }
 
-        if (!state->pending.empty()) break;
+        if (!state->pending.empty()) {
+          break;
+        }
 
         /* If there are no active or pending items, and the
            main thread is running process(), then no new items