diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index c5fa0a8..45ccaf9 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -122,3 +122,23 @@ jobs: - name: Run Clang Format run: clang-format --dry-run --Werror $(find include -type f) + + clang-tidy: + name: Clang Tidy + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Install + run: sudo apt-get install -y clang-tidy + + - name: Create Build Environment + run: cmake -E make_directory ${{github.workspace}}/build + + - name: Configure CMake + working-directory: ${{github.workspace}}/build + run: cmake ${{ github.workspace }} -DCMAKE_BUILD_TYPE=Debug -DCPP_CHANNEL_BUILD_TESTS=ON + + - name: Run Clang Tidy + run: clang-tidy -p ${{github.workspace}}/build $(find include -type f) -- -std=c++11 diff --git a/codecov.yml b/codecov.yml index af7fdad..c2d9be0 100644 --- a/codecov.yml +++ b/codecov.yml @@ -2,12 +2,12 @@ coverage: status: patch: default: - target: 96% + target: 90% threshold: 0% if_ci_failed: error project: default: - target: 94% + target: 90% threshold: 0% if_ci_failed: error ignore: diff --git a/include/msd/blocking_iterator.hpp b/include/msd/blocking_iterator.hpp index 35c1ade..dd66c1e 100644 --- a/include/msd/blocking_iterator.hpp +++ b/include/msd/blocking_iterator.hpp @@ -3,6 +3,7 @@ #ifndef MSD_CHANNEL_BLOCKING_ITERATOR_HPP_ #define MSD_CHANNEL_BLOCKING_ITERATOR_HPP_ +#include #include #include diff --git a/include/msd/channel.hpp b/include/msd/channel.hpp index 95e6005..35b5e20 100644 --- a/include/msd/channel.hpp +++ b/include/msd/channel.hpp @@ -109,7 +109,7 @@ class channel { { { std::unique_lock lock{mtx_}; - is_closed_.store(true); + is_closed_.store(true, std::memory_order_seq_cst); } cnd_.notify_all(); } @@ -120,7 +120,7 @@ class channel { * @return true If no more elements can be added to the channel. * @return false Otherwise. */ - NODISCARD bool closed() const noexcept { return is_closed_.load(); } + NODISCARD bool closed() const noexcept { return is_closed_.load(std::memory_order_seq_cst); } /** * @brief Returns an iterator to the beginning of the channel. @@ -169,46 +169,46 @@ class channel { }; template -channel::type>& operator<<(channel::type>& ch, T&& in) +channel::type>& operator<<(channel::type>& chan, T&& value) { { - std::unique_lock lock{ch.mtx_}; - ch.waitBeforeWrite(lock); + std::unique_lock lock{chan.mtx_}; + chan.waitBeforeWrite(lock); - if (ch.closed()) { + if (chan.closed()) { throw closed_channel{"cannot write on closed channel"}; } - ch.queue_.push(std::forward(in)); - ++ch.size_; + chan.queue_.push(std::forward(value)); + ++chan.size_; } - ch.cnd_.notify_one(); + chan.cnd_.notify_one(); - return ch; + return chan; } template -channel& operator>>(channel& ch, T& out) +channel& operator>>(channel& chan, T& out) { { - std::unique_lock lock{ch.mtx_}; - ch.waitBeforeRead(lock); + std::unique_lock lock{chan.mtx_}; + chan.waitBeforeRead(lock); - if (ch.closed() && ch.empty()) { - return ch; + if (chan.closed() && chan.empty()) { + return chan; } - if (!ch.empty()) { - out = std::move(ch.queue_.front()); - ch.queue_.pop(); - --ch.size_; + if (!chan.empty()) { + out = std::move(chan.queue_.front()); + chan.queue_.pop(); + --chan.size_; } } - ch.cnd_.notify_one(); + chan.cnd_.notify_one(); - return ch; + return chan; } } // namespace msd