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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     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