| 329 | } |
| 330 | |
| 331 | int TaskControl::parse_cpuset(std::string value, std::vector<unsigned>& cpus) { |
| 332 | static std::regex r("(\\d+-)?(\\d+)(,(\\d+-)?(\\d+))*"); |
| 333 | std::smatch match; |
| 334 | std::set<unsigned> cpuset; |
| 335 | if (value.empty()) { |
| 336 | return -1; |
| 337 | } |
| 338 | if (std::regex_match(value, match, r)) { |
| 339 | for (butil::StringSplitter split(value.data(), ','); split; ++split) { |
| 340 | butil::StringPiece cpu_ids(split.field(), split.length()); |
| 341 | cpu_ids.trim_spaces(); |
| 342 | butil::StringPiece begin = cpu_ids; |
| 343 | butil::StringPiece end = cpu_ids; |
| 344 | auto dash = cpu_ids.find('-'); |
| 345 | if (dash != cpu_ids.npos) { |
| 346 | begin = cpu_ids.substr(0, dash); |
| 347 | end = cpu_ids.substr(dash + 1); |
| 348 | } |
| 349 | unsigned first = UINT_MAX; |
| 350 | unsigned last = 0; |
| 351 | int ret; |
| 352 | ret = butil::StringSplitter(begin, '\t').to_uint(&first); |
| 353 | ret = ret | butil::StringSplitter(end, '\t').to_uint(&last); |
| 354 | if (ret != 0 || first > last) { |
| 355 | return -1; |
| 356 | } |
| 357 | for (auto i = first; i <= last; ++i) { |
| 358 | cpuset.insert(i); |
| 359 | } |
| 360 | } |
| 361 | cpus.assign(cpuset.begin(), cpuset.end()); |
| 362 | return 0; |
| 363 | } |
| 364 | return -1; |
| 365 | } |
| 366 | |
| 367 | void TaskControl::bind_thread_to_cpu(pthread_t pthread, unsigned cpu_id) { |
| 368 | #if defined(OS_LINUX) |
nothing calls this directly
no test coverage detected