* 设置线程亲和性,仅针对linux系统 */
| 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 | |
| 215 | private: |