Skip to content

Commit ab30bd0

Browse files
Run clang tidy (#62)
1 parent 51c7559 commit ab30bd0

File tree

4 files changed

+44
-23
lines changed

4 files changed

+44
-23
lines changed

.github/workflows/cmake.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,23 @@ jobs:
122122

123123
- name: Run Clang Format
124124
run: clang-format --dry-run --Werror $(find include -type f)
125+
126+
clang-tidy:
127+
name: Clang Tidy
128+
runs-on: ubuntu-latest
129+
130+
steps:
131+
- uses: actions/checkout@v4
132+
133+
- name: Install
134+
run: sudo apt-get install -y clang-tidy
135+
136+
- name: Create Build Environment
137+
run: cmake -E make_directory ${{github.workspace}}/build
138+
139+
- name: Configure CMake
140+
working-directory: ${{github.workspace}}/build
141+
run: cmake ${{ github.workspace }} -DCMAKE_BUILD_TYPE=Debug -DCPP_CHANNEL_BUILD_TESTS=ON
142+
143+
- name: Run Clang Tidy
144+
run: clang-tidy -p ${{github.workspace}}/build $(find include -type f) -- -std=c++11

codecov.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ coverage:
22
status:
33
patch:
44
default:
5-
target: 96%
5+
target: 90%
66
threshold: 0%
77
if_ci_failed: error
88
project:
99
default:
10-
target: 94%
10+
target: 90%
1111
threshold: 0%
1212
if_ci_failed: error
1313
ignore:

include/msd/blocking_iterator.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#ifndef MSD_CHANNEL_BLOCKING_ITERATOR_HPP_
44
#define MSD_CHANNEL_BLOCKING_ITERATOR_HPP_
55

6+
#include <cstddef>
67
#include <iterator>
78
#include <mutex>
89

include/msd/channel.hpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class channel {
109109
{
110110
{
111111
std::unique_lock<std::mutex> lock{mtx_};
112-
is_closed_.store(true);
112+
is_closed_.store(true, std::memory_order_seq_cst);
113113
}
114114
cnd_.notify_all();
115115
}
@@ -120,7 +120,7 @@ class channel {
120120
* @return true If no more elements can be added to the channel.
121121
* @return false Otherwise.
122122
*/
123-
NODISCARD bool closed() const noexcept { return is_closed_.load(); }
123+
NODISCARD bool closed() const noexcept { return is_closed_.load(std::memory_order_seq_cst); }
124124

125125
/**
126126
* @brief Returns an iterator to the beginning of the channel.
@@ -169,46 +169,46 @@ class channel {
169169
};
170170

171171
template <typename T>
172-
channel<typename std::decay<T>::type>& operator<<(channel<typename std::decay<T>::type>& ch, T&& in)
172+
channel<typename std::decay<T>::type>& operator<<(channel<typename std::decay<T>::type>& chan, T&& value)
173173
{
174174
{
175-
std::unique_lock<std::mutex> lock{ch.mtx_};
176-
ch.waitBeforeWrite(lock);
175+
std::unique_lock<std::mutex> lock{chan.mtx_};
176+
chan.waitBeforeWrite(lock);
177177

178-
if (ch.closed()) {
178+
if (chan.closed()) {
179179
throw closed_channel{"cannot write on closed channel"};
180180
}
181181

182-
ch.queue_.push(std::forward<T>(in));
183-
++ch.size_;
182+
chan.queue_.push(std::forward<T>(value));
183+
++chan.size_;
184184
}
185185

186-
ch.cnd_.notify_one();
186+
chan.cnd_.notify_one();
187187

188-
return ch;
188+
return chan;
189189
}
190190

191191
template <typename T>
192-
channel<T>& operator>>(channel<T>& ch, T& out)
192+
channel<T>& operator>>(channel<T>& chan, T& out)
193193
{
194194
{
195-
std::unique_lock<std::mutex> lock{ch.mtx_};
196-
ch.waitBeforeRead(lock);
195+
std::unique_lock<std::mutex> lock{chan.mtx_};
196+
chan.waitBeforeRead(lock);
197197

198-
if (ch.closed() && ch.empty()) {
199-
return ch;
198+
if (chan.closed() && chan.empty()) {
199+
return chan;
200200
}
201201

202-
if (!ch.empty()) {
203-
out = std::move(ch.queue_.front());
204-
ch.queue_.pop();
205-
--ch.size_;
202+
if (!chan.empty()) {
203+
out = std::move(chan.queue_.front());
204+
chan.queue_.pop();
205+
--chan.size_;
206206
}
207207
}
208208

209-
ch.cnd_.notify_one();
209+
chan.cnd_.notify_one();
210210

211-
return ch;
211+
return chan;
212212
}
213213

214214
} // namespace msd

0 commit comments

Comments
 (0)