MCPcopy Create free account
hub / github.com/NVIDIA/DALI / DoWait

Method DoWait

dali/core/exec/thread_pool_base.cc:31–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29
30template <bool cooperative>
31void JobBase<cooperative>::DoWait() {
32 if (wait_started_)
33 throw std::logic_error("This job has already been waited for.");
34
35 if (total_tasks_ == 0) {
36 // If there are no tasks, it's legal to skip a call to Run, therefore executor_ can be null.
37 wait_started_ = true;
38 wait_completed_ = true;
39 return;
40 }
41
42 if (this->executor_ == nullptr)
43 throw std::logic_error("This job hasn't been run - cannot wait for it.");
44
45 if (ThreadPoolBase::this_thread_pool() == this->executor_) {
46 if constexpr (cooperative) {
47 auto ready = [&]() { return num_pending_tasks_ == 0; };
48 wait_started_ = true;
49 bool result = ThreadPoolBase::this_thread_pool()->WaitOrRunTasks(this->cv_, ready);
50 wait_completed_ = true;
51 if (!result)
52 throw std::logic_error("The thread pool was stopped");
53 } else {
54 throw std::logic_error("Cannot wait for this job from inside the thread pool.");
55 }
56 } else {
57 wait_started_ = true;
58 int old = num_pending_tasks_.load();
59 while (old != 0) {
60 num_pending_tasks_.wait(old);
61 old = num_pending_tasks_.load();
62 assert(old >= 0);
63 }
64 wait_completed_ = true;
65 }
66}
67
68template <bool cooperative>
69void JobBase<cooperative>::DoNotify() {

Callers 1

WaitMethod · 0.80

Calls 4

this_thread_poolFunction · 0.85
WaitOrRunTasksMethod · 0.80
loadMethod · 0.45
waitMethod · 0.45

Tested by

no test coverage detected