summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2024-11-11 13:26:37 +0100
committerMaksim Denisov <denisov.maksim@huawei.com>2024-11-14 14:23:05 +0100
commit93842172d1b7ba6c5930f45208e2fab75bfef19b (patch)
tree7d079e7b98e5b1ada4faf3a5a0259b5954798779 /src
parente392e395fa0971f372698e43dbe388a92bb1948b (diff)
downloadjustbuild-93842172d1b7ba6c5930f45208e2fab75bfef19b.tar.gz
multithreading: Implement IWYU suggestions
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/multithreading/TARGETS10
-rw-r--r--src/buildtool/multithreading/async_map.hpp4
-rw-r--r--src/buildtool/multithreading/async_map_consumer.hpp8
-rw-r--r--src/buildtool/multithreading/async_map_node.hpp1
-rw-r--r--src/buildtool/multithreading/atomic_value.hpp2
-rw-r--r--src/buildtool/multithreading/notification_queue.hpp6
-rw-r--r--src/buildtool/multithreading/task.hpp1
-rw-r--r--src/buildtool/multithreading/task_system.cpp2
-rw-r--r--src/buildtool/multithreading/task_system.hpp2
9 files changed, 18 insertions, 18 deletions
diff --git a/src/buildtool/multithreading/TARGETS b/src/buildtool/multithreading/TARGETS
index fa76b3d4..b191714f 100644
--- a/src/buildtool/multithreading/TARGETS
+++ b/src/buildtool/multithreading/TARGETS
@@ -34,20 +34,14 @@
{ "type": ["@", "rules", "CC", "library"]
, "name": ["async_map"]
, "hdrs": ["async_map.hpp"]
- , "deps": ["async_map_node", "task", "task_system", ["@", "gsl", "", "gsl"]]
+ , "deps": ["async_map_node", "task_system", ["@", "gsl", "", "gsl"]]
, "stage": ["src", "buildtool", "multithreading"]
}
, "async_map_consumer":
{ "type": ["@", "rules", "CC", "library"]
, "name": ["async_map_consumer"]
, "hdrs": ["async_map_consumer.hpp"]
- , "deps":
- [ "async_map"
- , "async_map_node"
- , "task"
- , "task_system"
- , ["@", "gsl", "", "gsl"]
- ]
+ , "deps": ["async_map", "task_system", ["@", "gsl", "", "gsl"]]
, "stage": ["src", "buildtool", "multithreading"]
}
, "atomic_value":
diff --git a/src/buildtool/multithreading/async_map.hpp b/src/buildtool/multithreading/async_map.hpp
index e9bdd603..a3cdb58b 100644
--- a/src/buildtool/multithreading/async_map.hpp
+++ b/src/buildtool/multithreading/async_map.hpp
@@ -15,18 +15,20 @@
#ifndef INCLUDED_SRC_BUILDTOOL_MULTITHREADING_ASYNC_MAP_HPP
#define INCLUDED_SRC_BUILDTOOL_MULTITHREADING_ASYNC_MAP_HPP
+#include <algorithm>
#include <cstddef>
+#include <functional>
#include <memory>
#include <mutex> // unique_lock
#include <shared_mutex>
#include <thread>
+#include <tuple>
#include <unordered_map>
#include <utility> // std::make_pair to use std::unordered_map's emplace()
#include <vector>
#include "gsl/gsl"
#include "src/buildtool/multithreading/async_map_node.hpp"
-#include "src/buildtool/multithreading/task.hpp"
#include "src/buildtool/multithreading/task_system.hpp"
// Wrapper around map data structure for KeyT->AsyncMapNode<ValueT> that only
diff --git a/src/buildtool/multithreading/async_map_consumer.hpp b/src/buildtool/multithreading/async_map_consumer.hpp
index a523214e..484b2a52 100644
--- a/src/buildtool/multithreading/async_map_consumer.hpp
+++ b/src/buildtool/multithreading/async_map_consumer.hpp
@@ -15,12 +15,14 @@
#ifndef INCLUDED_SRC_BUILDTOOL_MULTITHREADING_ASYNC_MAP_CONSUMER_HPP
#define INCLUDED_SRC_BUILDTOOL_MULTITHREADING_ASYNC_MAP_CONSUMER_HPP
-#include <atomic>
-#include <condition_variable>
#include <cstddef>
#include <functional>
+#include <iterator>
+#include <memory>
#include <mutex>
+#include <optional>
#include <shared_mutex>
+#include <string>
#include <thread>
#include <unordered_map>
#include <unordered_set>
@@ -29,8 +31,6 @@
#include "gsl/gsl"
#include "src/buildtool/multithreading/async_map.hpp"
-#include "src/buildtool/multithreading/async_map_node.hpp"
-#include "src/buildtool/multithreading/task.hpp"
#include "src/buildtool/multithreading/task_system.hpp"
using AsyncMapConsumerLogger = std::function<void(std::string const&, bool)>;
diff --git a/src/buildtool/multithreading/async_map_node.hpp b/src/buildtool/multithreading/async_map_node.hpp
index 4cef35e9..f449d9c9 100644
--- a/src/buildtool/multithreading/async_map_node.hpp
+++ b/src/buildtool/multithreading/async_map_node.hpp
@@ -19,6 +19,7 @@
#include <mutex>
#include <optional>
#include <utility> // std::move
+#include <vector>
#include "gsl/gsl"
#include "src/buildtool/multithreading/task.hpp"
diff --git a/src/buildtool/multithreading/atomic_value.hpp b/src/buildtool/multithreading/atomic_value.hpp
index b8437cc7..28998c16 100644
--- a/src/buildtool/multithreading/atomic_value.hpp
+++ b/src/buildtool/multithreading/atomic_value.hpp
@@ -17,7 +17,7 @@
#include <atomic>
#include <functional>
-#include <optional>
+#include <memory>
#include "src/utils/cpp/atomic.hpp"
diff --git a/src/buildtool/multithreading/notification_queue.hpp b/src/buildtool/multithreading/notification_queue.hpp
index 4483b5be..8725177d 100644
--- a/src/buildtool/multithreading/notification_queue.hpp
+++ b/src/buildtool/multithreading/notification_queue.hpp
@@ -19,6 +19,7 @@
#include <condition_variable>
#include <cstddef>
#include <deque>
+#include <memory>
#include <mutex>
#include <optional>
#include <shared_mutex>
@@ -26,7 +27,8 @@
#include "gsl/gsl"
#include "src/buildtool/multithreading/task.hpp"
-#include "src/utils/cpp/atomic.hpp"
+// TODO(modernize): Remove pragma once underlying issue is solved
+#include "src/utils/cpp/atomic.hpp" // IWYU pragma: keep
// Counter that can block the caller until it reaches zero.
class WaitableZeroCounter {
@@ -59,7 +61,7 @@ class WaitableZeroCounter {
std::shared_mutex mutex_;
std::condition_variable_any cv_;
std::atomic<std::size_t> count_;
- std::atomic<bool> done_;
+ std::atomic<bool> done_ = false;
[[nodiscard]] auto IsZero() noexcept -> bool {
return count_ == 0 or done_;
diff --git a/src/buildtool/multithreading/task.hpp b/src/buildtool/multithreading/task.hpp
index 05331d75..7b9298ac 100644
--- a/src/buildtool/multithreading/task.hpp
+++ b/src/buildtool/multithreading/task.hpp
@@ -16,7 +16,6 @@
#define INCLUDED_SRC_BUILDTOOL_MULTITHREADING_TASK_HPP
#include <functional>
-#include <type_traits>
#include <utility> // std::move
class Task {
diff --git a/src/buildtool/multithreading/task_system.cpp b/src/buildtool/multithreading/task_system.cpp
index 13c3caec..8011e6ca 100644
--- a/src/buildtool/multithreading/task_system.cpp
+++ b/src/buildtool/multithreading/task_system.cpp
@@ -14,6 +14,8 @@
#include "src/buildtool/multithreading/task_system.hpp"
+#include <optional>
+
#include "gsl/gsl"
#include "src/buildtool/multithreading/task.hpp"
diff --git a/src/buildtool/multithreading/task_system.hpp b/src/buildtool/multithreading/task_system.hpp
index 95b4dedf..d2dfe402 100644
--- a/src/buildtool/multithreading/task_system.hpp
+++ b/src/buildtool/multithreading/task_system.hpp
@@ -76,7 +76,7 @@ class TaskSystem {
std::vector<std::thread> threads_;
std::vector<NotificationQueue> queues_;
std::atomic<std::size_t> index_{0};
- std::atomic<bool> shutdown_;
+ std::atomic<bool> shutdown_ = false;
WaitableZeroCounter total_workload_;
static constexpr std::size_t kNumberOfAttempts = 5;