MCPcopy Create free account
hub / github.com/ChunelFeng/CGraph / destroy

Method destroy

src/UtilsCtrl/ThreadPool/UThreadPool.cpp:141–178  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139
140
141CStatus UThreadPool::destroy() {
142 CGRAPH_FUNCTION_BEGIN
143 if (!is_init_) {
144 CGRAPH_FUNCTION_END
145 }
146
147 // primary 线程是普通指针,需要delete
148 for (const auto& pt : primary_threads_) {
149 CGRAPH_ASSERT_NOT_NULL(pt);
150 status += pt->destroy();
151 }
152 CGRAPH_FUNCTION_CHECK_STATUS
153
154 /**
155 * 这里之所以 destroy和 delete分开两个循环执行,
156 * 是因为当前线程被delete后,还可能存在未被delete的主线程,来steal当前线程的任务
157 * 在windows环境下,可能出现问题。
158 * destroy 和 delete 分开之后,不会出现此问题。
159 * 感谢 Ryan大佬(https://github.com/ryanhuang) 提供的帮助
160 */
161 for (auto &pt : primary_threads_) {
162 CGRAPH_DELETE_PTR(pt)
163 }
164 primary_threads_.clear();
165
166 // secondary 线程是智能指针,不需要delete
167 task_queue_.reset();
168 for (auto &st : secondary_threads_) {
169 CGRAPH_ASSERT_NOT_NULL(st.get());
170 status += st->destroy();
171 }
172 CGRAPH_FUNCTION_CHECK_STATUS
173 secondary_threads_.clear();
174 thread_record_map_.clear();
175 is_init_ = false;
176
177 CGRAPH_FUNCTION_END
178}
179
180
181CBool UThreadPool::isInit() const {

Callers 1

ifFunction · 0.45

Calls 3

CGRAPH_ASSERT_NOT_NULLFunction · 0.85
clearMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected