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

Function setAffinity

src/UtilsCtrl/ThreadPool/Thread/UThreadBase.h:196–212  ·  view source on GitHub ↗

* 设置线程亲和性,仅针对linux系统 */

Source from the content-addressed store, hash-verified

194 * 设置线程亲和性,仅针对linux系统
195 */
196 CVoid setAffinity(int index) {
197#if defined(__linux__) && !defined(__ANDROID__)
198 if (!config_->bind_cpu_enable_ || CGRAPH_CPU_NUM == 0 || index < 0) {
199 return;
200 }
201
202 cpu_set_t mask;
203 CPU_ZERO(&mask);
204 CPU_SET(index % CGRAPH_CPU_NUM, &mask);
205
206 auto handle = thread_.native_handle();
207 int ret = pthread_setaffinity_np(handle, sizeof(cpu_set_t), &mask);
208 if (0 != ret) {
209 CGRAPH_ECHO("warning : set thread affinity failed, system error code is [%d]", ret);
210 }
211#endif
212 }
213
214
215private:

Callers 1

initFunction · 0.85

Calls 1

CGRAPH_ECHOFunction · 0.85

Tested by

no test coverage detected