! \brief set the iterator before first location */
| 205 | } |
| 206 | /*! \brief set the iterator before first location */ |
| 207 | virtual void BeforeFirst(void) { |
| 208 | ThrowExceptionIfSet(); |
| 209 | std::unique_lock<std::mutex> lock(mutex_); |
| 210 | if (out_data_ != NULL) { |
| 211 | free_cells_.push(out_data_); |
| 212 | out_data_ = NULL; |
| 213 | } |
| 214 | if (producer_sig_.load(std::memory_order_acquire) == kDestroy) return; |
| 215 | |
| 216 | producer_sig_.store(kBeforeFirst, std::memory_order_release); |
| 217 | CHECK(!producer_sig_processed_.load(std::memory_order_acquire)); |
| 218 | if (nwait_producer_ != 0) { |
| 219 | producer_cond_.notify_one(); |
| 220 | } |
| 221 | CHECK(!producer_sig_processed_.load(std::memory_order_acquire)); |
| 222 | // wait until the request has been processed |
| 223 | consumer_cond_.wait(lock, [this]() { |
| 224 | return producer_sig_processed_.load(std::memory_order_acquire); |
| 225 | }); |
| 226 | producer_sig_processed_.store(false, std::memory_order_release); |
| 227 | bool notify = nwait_producer_ != 0 && !produce_end_; |
| 228 | lock.unlock(); |
| 229 | // notify producer, in case they are waiting for the condition. |
| 230 | if (notify) producer_cond_.notify_one(); |
| 231 | ThrowExceptionIfSet(); |
| 232 | } |
| 233 | |
| 234 | private: |
| 235 | /*! \brief not support BeforeFirst */ |