Producer: push with bounded blocking
| 36 | public: |
| 37 | // Producer: push with bounded blocking |
| 38 | bool push(const T& item) { |
| 39 | std::unique_lock<std::mutex> lock(mux_); |
| 40 | cv_space_.wait(lock, [this] { return count_ < N || !active_; }); |
| 41 | if (!active_) return false; |
| 42 | |
| 43 | buffer_[(head_ + count_) % N] = item; |
| 44 | ++count_; |
| 45 | lock.unlock(); |
| 46 | cv_data_.notify_one(); |
| 47 | return true; |
| 48 | } |
| 49 | |
| 50 | // Consumer: pop with blocking wait (Module 08: std::optional) |
| 51 | [[nodiscard]] std::optional<T> pop() { |
no outgoing calls