//! shuts the stream down. void Close() final { // close all sinks, this should emit sentinel to all other worker. for (size_t i = 0; i != sinks_.size(); ++i) { if (sinks_[i].closed()) continue; sinks_[i].Close(); } // close loop-back queue from this worker to all others on this host. for (size_t local_worker_id = 0; local_worker_id < multiplexer_.num_workers_per_host(); ++local_worker_id) { auto queue_ptr = multiplexer_.MixLoopback( id_, my_local_worker_id_, local_worker_id); if (!queue_ptr->write_closed()) queue_ptr->Close(); } // wait for close packets to arrive (this is a busy waiting loop, try to // do it better -tb) while (!queue_.write_closed()) { std::this_thread::sleep_for(std::chrono::milliseconds(10)); } tx_lifetime_.StopEventually(); tx_timespan_.StopEventually(); CallClosedCallbacksEventually(); }
//! return number of block in the queue. Use this ONLY for DEBUGGING! size_t size() { return queue_.size() - (write_closed() ? 1 : 0); }