180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/* 280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2012 Google Inc. 380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be 580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file. 680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkThreadUtils.h" 980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkThreadUtils_pthread.h" 1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include <mach/mach.h> 1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include <mach/thread_policy.h> 1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include <pthread.h> 1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querubool SkThread::setProcessorAffinity(unsigned int processor) { 1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkThread_PThreadData* pthreadData = static_cast<SkThread_PThreadData*>(fData); 1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru if (!pthreadData->fValidPThread) { 1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return false; 1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru } 2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru mach_port_t tid = pthread_mach_thread_np(pthreadData->fPThread); 2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru thread_affinity_policy_data_t policy; 2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru policy.affinity_tag = processor; 2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru return 0 == thread_policy_set(tid, 2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru THREAD_AFFINITY_POLICY, 2880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru (thread_policy_t) &policy, 2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru THREAD_AFFINITY_POLICY_COUNT); 3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru} 31