diff --git a/.clang-tidy b/.clang-tidy index aa5e578a53b61611ad8ea619967ce466c75d79ef..237902b68d1ee31c6571a70151333fd6e3538ce6 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -19,3 +19,5 @@ WarningsAsErrors: > clang-*, readability-*, performance-*, + +HeaderFilterRegex: emper/* diff --git a/emper/Actor.hpp b/emper/Actor.hpp index da6c6551bd7df0d7e1c7443201ae2a5d13bac464..f2b1d57baeb154369acf2a324edb4accf5d848eb 100644 --- a/emper/Actor.hpp +++ b/emper/Actor.hpp @@ -60,7 +60,7 @@ class Actor { void start() { if (state.load(std::memory_order_acquire) != Stopped) return; - Fiber* actorFiber = Fiber::from(std::bind(&Actor::actorLoop, this)); + Fiber* actorFiber = Fiber::from([this] { actorLoop(); }); if constexpr (callerEnvironment == CallerEnvironment::EMPER) { runtime.schedule(*actorFiber); } else { diff --git a/emper/Context.hpp b/emper/Context.hpp index 3428ccc203e9baabdc5c0d780f0a4f7b3e16824f..70727a12a9baf83b1658c0db506ac070885f706e 100644 --- a/emper/Context.hpp +++ b/emper/Context.hpp @@ -49,7 +49,7 @@ class ALIGN_TO_CACHE_LINE Context : Logger<LogSubsystem::C> { // NOLINTNEXTLINE(modernize-avoid-c-arrays) ALIGN_TO_CACHE_LINE char context[CONTEXT_SIZE]; - friend auto operator<<(std::ostream&, const Context&) -> std::ostream&; + friend auto operator<<(std::ostream& strm, const Context& context) -> std::ostream&; friend ContextManager; diff --git a/emper/Fiber.hpp b/emper/Fiber.hpp index 0449d3ba45369f55550d4d9e5bec1aa674d7c30f..01b6fba88c8408c3a1a40b9e149853c972a6947e 100644 --- a/emper/Fiber.hpp +++ b/emper/Fiber.hpp @@ -1,5 +1,5 @@ // SPDX-License-Identifier: LGPL-3.0-or-later -// Copyright © 2020 Florian Schmaus +// Copyright © 2020-2021 Florian Schmaus #pragma once #include <atomic> // for atomic_uint, atomic, __atomic_base, memory... @@ -110,7 +110,7 @@ class ALIGN_TO_CACHE_LINE Fiber : public Logger<LogSubsystem::F> { void print() const; - friend auto operator<<(std::ostream&, const Fiber&) -> std::ostream&; + friend auto operator<<(std::ostream& strm, const Fiber& fiber) -> std::ostream&; static inline auto from(fiber_fun_t function, void* arg) -> Fiber* { return new Fiber(std::move(function), arg); diff --git a/emper/Scheduler.hpp b/emper/Scheduler.hpp index e563cbd2b68b4a0c8dbce217d99737f69f6fbfba..eea2ff98c81d7fe95097ee5485a19b53515140bc 100644 --- a/emper/Scheduler.hpp +++ b/emper/Scheduler.hpp @@ -47,7 +47,7 @@ class Scheduler : public Logger<LogSubsystem::SCHED> { void enqueueInAnywhereQueue(Fiber& fiber) { scheduleAnywhereQueue.enqueue(&fiber); } - auto dequeFiberFromAnywhereQueue() -> Fiber* { return scheduleAnywhereQueue.dequeue(); } + auto dequeueFiberFromAnywhereQueue() -> Fiber* { return scheduleAnywhereQueue.dequeue(); } virtual void scheduleInternal(Fiber& fiber) = 0; diff --git a/emper/io/Future.hpp b/emper/io/Future.hpp index 76baee9c64ddc1ca249c02ad1e18b36bf2edc410..772cd74ea707f402b2631f95d97b37d3c296b7f0 100644 --- a/emper/io/Future.hpp +++ b/emper/io/Future.hpp @@ -117,12 +117,12 @@ class Future : public Logger<LogSubsystem::IO> { cancel(); } - inline auto isRetrieved() -> bool { return state.retrieved; } - inline auto isSubmitted() -> bool { return state.submitted; } - inline auto isCompleted() -> bool { return state.completed; } - inline auto isCancelled() -> bool { return state.cancelled; } - inline auto isDependency() -> bool { return state.dependency; } - inline auto isForgotten() -> bool { return state.forgotten; } + [[nodiscard]] auto isRetrieved() const -> bool { return state.retrieved; } + [[nodiscard]] auto isSubmitted() const -> bool { return state.submitted; } + [[nodiscard]] auto isCompleted() const -> bool { return state.completed; } + [[nodiscard]] auto isCancelled() const -> bool { return state.cancelled; } + [[nodiscard]] auto isDependency() const -> bool { return state.dependency; } + [[nodiscard]] auto isForgotten() const -> bool { return state.forgotten; } /* * @brief reset the Future @@ -222,9 +222,9 @@ class Future : public Logger<LogSubsystem::IO> { friend auto operator<<(std::ostream& os, const Future* f) -> std::ostream& { if (f) { return os << *f; - } else { - return os << "Future nullptr"; } + + return os << "Future nullptr"; } }; @@ -280,7 +280,7 @@ class PartialCompletableFuture : public Future { /** * Used for Stats::recordCompletion double dispatch */ - virtual void recordCompletion(Stats& stats, int32_t res) override { + void recordCompletion(Stats& stats, int32_t res) override { if constexpr (emper::STATS) { recordCompletionInternal(stats, res); } diff --git a/emper/io/IoContext.hpp b/emper/io/IoContext.hpp index 943f6206e6bc3cf5a8f1c34db74748101a38760f..37081f41212058bc9aee13f139288cd5b8c559d4 100644 --- a/emper/io/IoContext.hpp +++ b/emper/io/IoContext.hpp @@ -37,7 +37,7 @@ class IoContext : public Logger<LogSubsystem::IO> { static pthread_t globalCompleter; /* function executed by the global completer thread */ - static auto globalCompleterFunc(void *) -> void *; + static auto globalCompleterFunc(void *arg) -> void *; // start the global completer thread // this must be called after all worker IoContexts' eventfds are submitted diff --git a/emper/io/Stats.hpp b/emper/io/Stats.hpp index 08824aa151e47c2e57e46f75ef0ddd998ce79f22..95afacb111fab842b6158bb91c4e2adc710e210a 100644 --- a/emper/io/Stats.hpp +++ b/emper/io/Stats.hpp @@ -68,7 +68,7 @@ class Stats { * 6: immediate resubmissions */ - typedef std::map<Operation, std::map<CompletionType, uint64_t>> CompletionMap; + using CompletionMap = std::map<Operation, std::map<CompletionType, uint64_t>>; CompletionMap io_uring_completions = { {Operation::SEND, @@ -128,7 +128,7 @@ class Stats { void recordCompletion(const WritevFuture& f, const int32_t& res) { size_t exp = 0; - auto iov = reinterpret_cast<const struct iovec*>(f.buf); + const auto* iov = reinterpret_cast<const struct iovec*>(f.buf); for (unsigned i = 0; i < f.len; ++i) { exp += iov[i].iov_len; } diff --git a/emper/lib/adt/LockedSet.hpp b/emper/lib/adt/LockedSet.hpp index e3e1b1928a1e037cd3f2dbcf391c106c9f39a4a6..7c4cccfdd8c4324fbd67bb33f9242b660ade1857 100644 --- a/emper/lib/adt/LockedSet.hpp +++ b/emper/lib/adt/LockedSet.hpp @@ -27,7 +27,7 @@ class LockedSet { _set.insert(first, last); } - size_t erase(const Key& key) { + auto erase(const Key& key) -> size_t { std::lock_guard<std::mutex> lock(_mutex); return _set.erase(key); } diff --git a/emper/strategies/AbstractWorkStealingScheduler.cpp b/emper/strategies/AbstractWorkStealingScheduler.cpp index 9067ca8aec13f13bf6a9bd9166752a0b553ec301..a811f66b5a0854837990b68f6b4ff635742069ad 100644 --- a/emper/strategies/AbstractWorkStealingScheduler.cpp +++ b/emper/strategies/AbstractWorkStealingScheduler.cpp @@ -89,14 +89,14 @@ auto AbstractWorkStealingScheduler::nextFiberViaWorkStealing() -> std::pair<Fibe } // Try the "scheduled from anywhere" queue to get work as last resort. - fiber = dequeFiberFromAnywhereQueue(); + fiber = dequeueFiberFromAnywhereQueue(); if (fiber) { if constexpr (emper::STATS) { abstractWorkStealingStrategy.nextFiberFromAnywhereQueue.fetch_add(1, std::memory_order_relaxed); } - fiberSource = FiberSource::anywhere_queue; + fiberSource = FiberSource::anywhereQueue; goto out; } diff --git a/emper/strategies/AbstractWorkStealingScheduler.hpp b/emper/strategies/AbstractWorkStealingScheduler.hpp index acd17d7b48052177bbc64b96c8d781cd472da70d..6e3564fbff751295b87f32fa8462242dcbe0b5d6 100644 --- a/emper/strategies/AbstractWorkStealingScheduler.hpp +++ b/emper/strategies/AbstractWorkStealingScheduler.hpp @@ -36,10 +36,10 @@ class AbstractWorkStealingScheduler : public Scheduler { public: static const int QUEUE_SIZE = 1024; - enum struct FiberSource : uintptr_t { + enum class FiberSource : uintptr_t { local, stolen, - anywhere_queue, + anywhereQueue, }; protected: diff --git a/emper/strategies/laws/LawsDispatcher.cpp b/emper/strategies/laws/LawsDispatcher.cpp index 2deca760c2d806e7d1b4768cba9b19ba75e965c3..94a82e7bc83562d6bfae8c0f3ffe767655316922 100644 --- a/emper/strategies/laws/LawsDispatcher.cpp +++ b/emper/strategies/laws/LawsDispatcher.cpp @@ -44,7 +44,7 @@ void LawsDispatcher::dispatchLoop() { case LawsStrategy::FiberSource::stolen: lawsStrategy.dispatchedFiberStolen.fetch_add(1, std::memory_order_relaxed); break; - case LawsStrategy::FiberSource::anywhere_queue: + case LawsStrategy::FiberSource::anywhereQueue: lawsStrategy.dispatchedFiberFromAnywhere.fetch_add(1, std::memory_order_relaxed); break; default: diff --git a/emper/strategies/laws/LawsStrategy.hpp b/emper/strategies/laws/LawsStrategy.hpp index 6d672ee0079890be64724656f14b18e701e2ebf1..d06448689b0664c3d2d30c606ae2d1f5cc07ba20 100644 --- a/emper/strategies/laws/LawsStrategy.hpp +++ b/emper/strategies/laws/LawsStrategy.hpp @@ -18,11 +18,11 @@ class RuntimeStrategyStats; class LawsStrategy : public AbstractWorkStealingStrategy { private: - enum struct FiberSource : uintptr_t { + enum class FiberSource : uintptr_t { local = static_cast<uintptr_t>(AbstractWorkStealingScheduler::FiberSource::local), stolen = static_cast<uintptr_t>(AbstractWorkStealingScheduler::FiberSource::stolen), - anywhere_queue = - static_cast<uintptr_t>(AbstractWorkStealingScheduler::FiberSource::anywhere_queue), + anywhereQueue = + static_cast<uintptr_t>(AbstractWorkStealingScheduler::FiberSource::anywhereQueue), fromPriority, }; diff --git a/tests/AlarmActorTest.cpp b/tests/AlarmActorTest.cpp index d3c5e340e4236e6009957958872eab559f8ad5ca..a0f962b60f994a2699a842b385ef24639a18c903 100644 --- a/tests/AlarmActorTest.cpp +++ b/tests/AlarmActorTest.cpp @@ -1,9 +1,8 @@ // SPDX-License-Identifier: LGPL-3.0-or-later -// Copyright © 2020 Florian Fischer -#include <cstdlib> // for exit, EXIT_FAILURE, EXIT_SUC... -#include <functional> // bind -#include <iostream> // for operator<<, basic_ostream -#include <thread> // for hardware_concurrency +// Copyright © 2020 Florian Fischer, 2021 Florian Schmaus +#include <cstdlib> // for exit, EXIT_FAILURE, EXIT_SUC... +#include <iostream> // for operator<<, basic_ostream +#include <thread> // for hardware_concurrency #include "Actor.hpp" // for Actor #include "BinaryPrivateSemaphore.hpp" // for BPS diff --git a/tests/SimpleActorTest.cpp b/tests/SimpleActorTest.cpp index 574468568fd08e172f288d0d89c7143bc7cd03d5..3415863c08a9332fbe78fc7eda651f96ecbfaa27 100644 --- a/tests/SimpleActorTest.cpp +++ b/tests/SimpleActorTest.cpp @@ -1,10 +1,9 @@ // SPDX-License-Identifier: LGPL-3.0-or-later -// Copyright © 2020 Florian Schmaus -#include <atomic> // for atomic_thread_fence, memory_... -#include <cstdint> // for uint64_t -#include <cstdlib> // for exit, EXIT_FAILURE, EXIT_SUC... -#include <functional> // for bind -#include <iostream> // for operator<<, basic_ostream +// Copyright © 2020-2021 Florian Schmaus +#include <atomic> // for atomic_thread_fence, memory_... +#include <cstdint> // for uint64_t +#include <cstdlib> // for exit, EXIT_FAILURE, EXIT_SUC... +#include <iostream> // for operator<<, basic_ostream #include "Actor.hpp" // for Actor #include "CountingPrivateSemaphore.hpp" // for CPS diff --git a/tests/TellActorFromAnywhereTest.cpp b/tests/TellActorFromAnywhereTest.cpp index bedfbd6d83a16d5e03e593eaa1642ecd7c07f2db..70800ac153e3fa9fce342659631138f7a75d805c 100644 --- a/tests/TellActorFromAnywhereTest.cpp +++ b/tests/TellActorFromAnywhereTest.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: LGPL-3.0-or-later -// Copyright © 2020 Florian Schmaus -#include <functional> // for bind +// Copyright © 2020-2021 Florian Schmaus #include <thread> #include "Actor.hpp" diff --git a/tests/UnblockOnMainActorTest.cpp b/tests/UnblockOnMainActorTest.cpp index 43c9def73ede3cdefd186a53325bc874686e853f..020db28f5dc8242054a729fb65b1613676f14a5d 100644 --- a/tests/UnblockOnMainActorTest.cpp +++ b/tests/UnblockOnMainActorTest.cpp @@ -1,11 +1,10 @@ // SPDX-License-Identifier: LGPL-3.0-or-later -// Copyright © 2020 Florian Fischer -#include <atomic> // for atomic -#include <cstdlib> // for exit, EXIT_FAILURE, EXIT_SUC... -#include <ctime> // for nanosleep, timespec -#include <functional> // bind -#include <iostream> // for operator<<, basic_ostream -#include <thread> // for this_thread +// Copyright © 2020 Florian Fischer, 2021 Florian Schmaus +#include <atomic> // for atomic +#include <cstdlib> // for exit, EXIT_FAILURE, EXIT_SUC... +#include <ctime> // for nanosleep, timespec +#include <iostream> // for operator<<, basic_ostream +#include <thread> // for this_thread #include "Actor.hpp" // for Actor #include "BinaryPrivateSemaphore.hpp" // for BPS