3 #include <torch/data/detail/queue.h> 4 #include <torch/types.h> 6 #include <c10/util/Exception.h> 7 #include <c10/util/Optional.h> 25 template <
typename Job,
typename Result>
30 new_jobs_.
push(std::move(job));
36 results_.
push(std::move(result));
42 return new_jobs_.
pop();
49 if (in_flight_jobs_ > 0) {
50 auto result = results_.
pop(timeout);
61 auto number_cleared = new_jobs_.
clear();
62 in_flight_jobs_ -= number_cleared;
64 while (in_flight_jobs_ > 0) {
72 return in_flight_jobs_;
80 size_t in_flight_jobs_ = 0;
Job pop_job()
Returns the next job, blocking until there is one available.
size_t in_flight_jobs() const noexcept
Returns the number of jobs that are still in progress.
size_t clear()
Empties the queue and returns the number of elements that were present at the start of the function...
optional< Result > pop_result(optional< std::chrono::milliseconds > timeout=nullopt)
Returns the result of a job, or nullopt if all jobs were exhausted.
void push_job(Job job)
Pushes a new job. Called by the main thread.
Encapsulates the full life cycle of DataLoader jobs.
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...
void push_result(Result result)
Pushes the result of a job. Called by worker threads.
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.
void drain()
Discards any jobs that are not yet in flight, and waits for all in-flight jobs to finish...