MCPcopy Create free account
hub / github.com/apache/brpc / parse_cpuset

Method parse_cpuset

src/bthread/task_control.cpp:331–365  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

329}
330
331int 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
367void TaskControl::bind_thread_to_cpu(pthread_t pthread, unsigned cpu_id) {
368#if defined(OS_LINUX)

Callers

nothing calls this directly

Calls 13

StringSplitterClass · 0.85
fieldMethod · 0.80
trim_spacesMethod · 0.80
substrMethod · 0.80
to_uintMethod · 0.80
emptyMethod · 0.45
dataMethod · 0.45
lengthMethod · 0.45
findMethod · 0.45
insertMethod · 0.45
assignMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected