Как установить привязку процессора к потоку, используемому spdlog, при использовании spdlog для входа в режим asyn c? - PullRequest
0 голосов
/ 26 марта 2020

Я использую spdlog для входа в асин c режим. Я хочу назначить задачу регистрации только для одного ядра процессора. Есть ли API для достижения этого в spdlog?

1 Ответ

0 голосов
/ 26 марта 2020

На данный момент у меня есть обходной путь для установки соответствия при создании пула потоков в файле библиотеки threadpool-inl.h

SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items, size_t threads_n, std::function<void()> on_thread_start)
    : q_(q_max_items)
{
    //printf("number of threads %lu", threads_n);
    if (threads_n == 0 || threads_n > 1000)
    {
        throw_spdlog_ex("spdlog::thread_pool(): invalid threads_n param (valid "
                        "range is 1-1000)");
    }
    for (size_t i = 0; i < threads_n; i++)
    {
        threads_.emplace_back([this, on_thread_start] {
            on_thread_start();
            this->thread_pool::worker_loop_();
        });
        // Create a cpu_set_t object representing a set of CPUs. Clear it and mark only CPU 2 as set.
        cpu_set_t cpuset;
        CPU_ZERO(&cpuset);
        CPU_SET(2, &cpuset);
        int rc = pthread_setaffinity_np(threads_[i].native_handle(), sizeof(cpu_set_t), &cpuset);
        if (rc != 0) {
            printf( "Error calling pthread_setaffinity_np: %d \n", rc);
        }
    }
}
...