1111#include < type_traits>
1212
1313#include " blocking_iterator.hpp"
14+ #include " nodiscard.hpp"
1415
1516namespace msd {
1617
17- #if (__cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L))
18- #define NODISCARD [[nodiscard]]
19- #else
20- #define NODISCARD
21- #endif
22-
2318/* *
2419 * @brief Exception thrown if trying to write on closed channel.
2520 */
@@ -134,11 +129,9 @@ class channel {
134129 return false ;
135130 }
136131
137- if (!(size_ == 0 )) {
138- out = std::move (queue_.front ());
139- queue_.pop ();
140- --size_;
141- }
132+ out = std::move (queue_.front ());
133+ queue_.pop ();
134+ --size_;
142135 }
143136
144137 cnd_.notify_one ();
@@ -202,7 +195,7 @@ class channel {
202195 NODISCARD bool drained () noexcept
203196 {
204197 std::unique_lock<std::mutex> lock{mtx_};
205- return is_closed_ && size_ == 0 ;
198+ return size_ == 0 && is_closed_ ;
206199 }
207200
208201 /* *
@@ -238,7 +231,7 @@ class channel {
238231
239232 void waitBeforeRead (std::unique_lock<std::mutex>& lock)
240233 {
241- cnd_.wait (lock, [this ]() { return !( size_ == 0 ) || is_closed_; });
234+ cnd_.wait (lock, [this ]() { return size_ > 0 || is_closed_; });
242235 };
243236
244237 void waitBeforeWrite (std::unique_lock<std::mutex>& lock)
@@ -247,8 +240,6 @@ class channel {
247240 cnd_.wait (lock, [this ]() { return size_ < cap_; });
248241 }
249242 }
250-
251- friend class blocking_iterator <channel>;
252243};
253244
254245template <typename T>
0 commit comments