gfx/skia/trunk/src/utils/SkThreadUtils_pthread_linux.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /*
     2  * Copyright 2012 Google Inc.
     3  *
     4  * Use of this source code is governed by a BSD-style license that can be
     5  * found in the LICENSE file.
     6  */
     8 #ifndef _GNU_SOURCE
     9 #define _GNU_SOURCE //for pthread_setaffinity_np
    10 #endif
    12 #include "SkThreadUtils.h"
    13 #include "SkThreadUtils_pthread.h"
    15 #include <pthread.h>
    17 static int nth_set_cpu(unsigned int n, cpu_set_t* cpuSet) {
    18     n %= CPU_COUNT(cpuSet);
    19     for (unsigned int setCpusSeen = 0, currentCpu = 0; true; ++currentCpu) {
    20         if (CPU_ISSET(currentCpu, cpuSet)) {
    21             ++setCpusSeen;
    22             if (setCpusSeen > n) {
    23                 return currentCpu;
    24             }
    25         }
    26     }
    27 }
    29 bool SkThread::setProcessorAffinity(unsigned int processor) {
    30     SkThread_PThreadData* pthreadData = static_cast<SkThread_PThreadData*>(fData);
    31     if (!pthreadData->fValidPThread) {
    32         return false;
    33     }
    35     cpu_set_t parentCpuset;
    36     if (0 != pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t), &parentCpuset)) {
    37         return false;
    38     }
    40     cpu_set_t cpuset;
    41     CPU_ZERO(&cpuset);
    42     CPU_SET(nth_set_cpu(processor, &parentCpuset), &cpuset);
    43     return 0 == pthread_setaffinity_np(pthreadData->fPThread,
    44                                        sizeof(cpu_set_t),
    45                                        &cpuset);
    46 }

mercurial