7eaf875a0986c457be5e459dc669b215c050bd98vboxsync/* $Id$ */
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync/** @file
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync * IPRT - Generic RTThreadSetAffinityToCpu implementation.
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync */
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync/*
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync * Copyright (C) 2011 Oracle Corporation
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync *
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync * available from http://www.virtualbox.org. This file is free software;
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync * you can redistribute it and/or modify it under the terms of the GNU
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync * General Public License (GPL) as published by the Free Software
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync *
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync * The contents of this file may alternatively be used under the terms
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync * of the Common Development and Distribution License Version 1.0
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync * VirtualBox OSE distribution, in which case the provisions of the
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync * CDDL are applicable instead of those of the GPL.
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync *
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync * You may elect to license modified versions of this file under the
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync * terms and conditions of either the GPL or the CDDL or both.
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync */
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync/*******************************************************************************
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync* Header Files *
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync*******************************************************************************/
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync#include <iprt/thread.h>
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync#include "internal/iprt.h"
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync#include <iprt/cpuset.h>
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync#include <iprt/err.h>
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync
7eaf875a0986c457be5e459dc669b215c050bd98vboxsyncRTR3DECL(int) RTThreadSetAffinityToCpu(RTCPUID idCpu)
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync{
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync int rc;
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync if (idCpu == NIL_RTCPUID)
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync rc = RTThreadSetAffinity(NULL);
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync else
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync {
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync int iCpu = RTMpCpuIdToSetIndex(idCpu);
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync if (iCpu >= 0)
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync {
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync RTCPUSET CpuSet;
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync RTCpuSetEmpty(&CpuSet);
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync RTCpuSetAddByIndex(&CpuSet, iCpu);
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync rc = RTThreadSetAffinity(&CpuSet);
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync }
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync else
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync rc = VERR_CPU_NOT_FOUND;
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync }
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync return rc;
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync}
7eaf875a0986c457be5e459dc669b215c050bd98vboxsync