3 #include <torch/types.h> 5 #include <c10/util/Exception.h> 8 #include <condition_variable> 33 std::lock_guard<std::mutex> lock(mutex_);
34 queue_.push(std::move(value));
44 std::unique_lock<std::mutex> lock(mutex_);
47 lock, *timeout, [
this] { return !this->queue_.empty(); })) {
50 "Timeout in DataLoader queue while waiting for next batch" 51 " (timeout was ", timeout->count(),
" ms)");
55 cv_.wait(lock, [
this] {
return !this->queue_.empty(); });
57 AT_ASSERT(!queue_.empty());
58 T value = queue_.front();
69 std::lock_guard<std::mutex> lock(this->mutex_);
70 const auto size = queue_.size();
71 while (!queue_.empty()) {
80 std::condition_variable cv_;
size_t clear()
Empties the queue and returns the number of elements that were present at the start of the function...
A basic locked, blocking MPMC queue.
void push(T value)
Pushes a new value to the back of the Queue and notifies one thread on the waiting side about this ev...
T pop(optional< std::chrono::milliseconds > timeout=nullopt)
Blocks until at least one element is ready to be popped from the front of the queue.