MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / worker_impl

Method worker_impl

src/core/impl/utils/async_worker.cpp:79–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77}
78
79void AsyncWorkerSet::worker_impl(const Task& task) {
80 size_t cur_finished_call = m_nr_start_call;
81 m_worker_init_finished.store(true);
82
83 for (;;) {
84 std::unique_lock<std::mutex> lk(m_mtx);
85 if (m_should_stop)
86 return;
87 size_t dst_nr_call = m_nr_start_call;
88
89 if (cur_finished_call < dst_nr_call) {
90 lk.unlock();
91
92 while (cur_finished_call < dst_nr_call) {
93 if (m_should_stop)
94 return;
95 task();
96 cur_finished_call++;
97 }
98
99 lk.lock();
100
101 // check stop flag whenever lock is acquired
102 if (m_should_stop)
103 return;
104
105 if (cur_finished_call == m_nr_start_call) {
106 mgb_assert(m_nr_worker_to_wait);
107 m_nr_worker_to_wait--;
108 m_cv_finish.notify_one();
109 lk.unlock();
110 }
111 } else {
112 m_cv_start.wait(lk);
113 }
114 }
115}
116
117void AsyncWorkerSet::check_exception() {
118#if MGB_ENABLE_EXCEPTION

Callers

nothing calls this directly

Calls 4

storeMethod · 0.45
unlockMethod · 0.45
lockMethod · 0.45
waitMethod · 0.45

Tested by

no test coverage detected