Home | History | Annotate | Download | only in utils
      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  */
      7 
      8 #include "SkThreadUtils.h"
      9 #include "SkThreadUtils_pthread.h"
     10 
     11 #include <mach/mach.h>
     12 #include <mach/thread_policy.h>
     13 #include <pthread.h>
     14 
     15 bool SkThread::setProcessorAffinity(unsigned int processor) {
     16     SkThread_PThreadData* pthreadData = static_cast<SkThread_PThreadData*>(fData);
     17     if (!pthreadData->fValidPThread) {
     18         return false;
     19     }
     20 
     21     mach_port_t tid = pthread_mach_thread_np(pthreadData->fPThread);
     22 
     23     thread_affinity_policy_data_t policy;
     24     policy.affinity_tag = processor;
     25 
     26     return 0 == thread_policy_set(tid,
     27                                   THREAD_AFFINITY_POLICY,
     28                                   (thread_policy_t) &policy,
     29                                   THREAD_AFFINITY_POLICY_COUNT);
     30 }
     31