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

Function setAffinity

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

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

Source from the content-addressed store, hash-verified

148 * 设置线程亲和性,仅针对linux系统
149 */
150 CVoid setAffinity(int index) {
151#ifdef __linux__
152 if (!config_->bind_cpu_enable_ || CGRAPH_CPU_NUM == 0 || index < 0) {
153 return;
154 }
155
156 cpu_set_t mask;
157 CPU_ZERO(&mask);
158 CPU_SET(index % CGRAPH_CPU_NUM, &mask);
159
160 auto handle = thread_.native_handle();
161 int ret = pthread_setaffinity_np(handle, sizeof(cpu_set_t), &mask);
162 if (0 != ret) {
163 CGRAPH_ECHO("warning : set thread affinity failed, error code is [%d]", ret);
164 }
165#endif
166 }
167
168
169private:

Callers 1

initFunction · 0.85

Calls 1

CGRAPH_ECHOFunction · 0.85

Tested by

no test coverage detected