diff -r 000000000000 -r 6474c204b198 gfx/skia/trunk/src/utils/SkThreadUtils_pthread_linux.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gfx/skia/trunk/src/utils/SkThreadUtils_pthread_linux.cpp Wed Dec 31 06:09:35 2014 +0100 @@ -0,0 +1,46 @@ +/* + * Copyright 2012 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE //for pthread_setaffinity_np +#endif + +#include "SkThreadUtils.h" +#include "SkThreadUtils_pthread.h" + +#include + +static int nth_set_cpu(unsigned int n, cpu_set_t* cpuSet) { + n %= CPU_COUNT(cpuSet); + for (unsigned int setCpusSeen = 0, currentCpu = 0; true; ++currentCpu) { + if (CPU_ISSET(currentCpu, cpuSet)) { + ++setCpusSeen; + if (setCpusSeen > n) { + return currentCpu; + } + } + } +} + +bool SkThread::setProcessorAffinity(unsigned int processor) { + SkThread_PThreadData* pthreadData = static_cast(fData); + if (!pthreadData->fValidPThread) { + return false; + } + + cpu_set_t parentCpuset; + if (0 != pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t), &parentCpuset)) { + return false; + } + + cpu_set_t cpuset; + CPU_ZERO(&cpuset); + CPU_SET(nth_set_cpu(processor, &parentCpuset), &cpuset); + return 0 == pthread_setaffinity_np(pthreadData->fPThread, + sizeof(cpu_set_t), + &cpuset); +}