mp-win.cpp revision e64031e20c39650a7bc902a3e1aba613b9415dee
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync/* $Id$ */
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync/** @file
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync * IPRT - Multiprocessor, Windows.
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync */
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync/*
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2006-2007 Oracle Corporation
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync *
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync * available from http://www.virtualbox.org. This file is free software;
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync * you can redistribute it and/or modify it under the terms of the GNU
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync * General Public License (GPL) as published by the Free Software
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync *
0d12c7f9423f2745f8e282523d0930f91bff03b3vboxsync * The contents of this file may alternatively be used under the terms
0d12c7f9423f2745f8e282523d0930f91bff03b3vboxsync * of the Common Development and Distribution License Version 1.0
0d12c7f9423f2745f8e282523d0930f91bff03b3vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
0d12c7f9423f2745f8e282523d0930f91bff03b3vboxsync * VirtualBox OSE distribution, in which case the provisions of the
0d12c7f9423f2745f8e282523d0930f91bff03b3vboxsync * CDDL are applicable instead of those of the GPL.
0d12c7f9423f2745f8e282523d0930f91bff03b3vboxsync *
0d12c7f9423f2745f8e282523d0930f91bff03b3vboxsync * You may elect to license modified versions of this file under the
0d12c7f9423f2745f8e282523d0930f91bff03b3vboxsync * terms and conditions of either the GPL or the CDDL or both.
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync */
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync/*******************************************************************************
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync* Header Files *
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync*******************************************************************************/
032a52c5b2984e26e84c2961f8f7f98a3954c8f2vboxsync#define LOG_GROUP RTLOGGROUP_SYSTEM
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync#include <Windows.h>
590bfe12ce22cd3716448fbb9f4dc51664bfe5e2vboxsync#include <iprt/mp.h>
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync#include <iprt/cpuset.h>
45c3e41d012100c5f4a3f77e391e4c6da8f5b97avboxsync#include <iprt/assert.h>
45c3e41d012100c5f4a3f77e391e4c6da8f5b97avboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync/** @todo RTmpCpuId(). */
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsyncRTDECL(int) RTMpCpuIdToSetIndex(RTCPUID idCpu)
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync{
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync return idCpu < MAXIMUM_PROCESSORS ? idCpu : -1;
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync}
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsyncRTDECL(RTCPUID) RTMpCpuIdFromSetIndex(int iCpu)
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync{
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync return (unsigned)iCpu < MAXIMUM_PROCESSORS ? iCpu : NIL_RTCPUID;
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync}
c2046db2cc346cc299f0cd9b2d1e160179159cfcvboxsync
9939c713bffcfc4305d99d994552aa2ad9bce097vboxsync
c2046db2cc346cc299f0cd9b2d1e160179159cfcvboxsyncRTDECL(RTCPUID) RTMpGetMaxCpuId(void)
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync{
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync return MAXIMUM_PROCESSORS - 1;
c2046db2cc346cc299f0cd9b2d1e160179159cfcvboxsync}
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
c2046db2cc346cc299f0cd9b2d1e160179159cfcvboxsync
c2046db2cc346cc299f0cd9b2d1e160179159cfcvboxsyncRTDECL(bool) RTMpIsCpuOnline(RTCPUID idCpu)
c2046db2cc346cc299f0cd9b2d1e160179159cfcvboxsync{
c2046db2cc346cc299f0cd9b2d1e160179159cfcvboxsync RTCPUSET Set;
c2046db2cc346cc299f0cd9b2d1e160179159cfcvboxsync return RTCpuSetIsMember(RTMpGetOnlineSet(&Set), idCpu);
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync}
044af0d1e6474076366759db86f101778c5f20ccvboxsync
044af0d1e6474076366759db86f101778c5f20ccvboxsync
044af0d1e6474076366759db86f101778c5f20ccvboxsyncRTDECL(bool) RTMpIsCpuPossible(RTCPUID idCpu)
044af0d1e6474076366759db86f101778c5f20ccvboxsync{
044af0d1e6474076366759db86f101778c5f20ccvboxsync RTCPUSET Set;
044af0d1e6474076366759db86f101778c5f20ccvboxsync return RTCpuSetIsMember(RTMpGetSet(&Set), idCpu);
044af0d1e6474076366759db86f101778c5f20ccvboxsync}
044af0d1e6474076366759db86f101778c5f20ccvboxsync
044af0d1e6474076366759db86f101778c5f20ccvboxsync
044af0d1e6474076366759db86f101778c5f20ccvboxsyncRTDECL(PRTCPUSET) RTMpGetSet(PRTCPUSET pSet)
044af0d1e6474076366759db86f101778c5f20ccvboxsync{
044af0d1e6474076366759db86f101778c5f20ccvboxsync RTCPUID idCpu = RTMpGetCount();
044af0d1e6474076366759db86f101778c5f20ccvboxsync RTCpuSetEmpty(pSet);
044af0d1e6474076366759db86f101778c5f20ccvboxsync while (idCpu-- > 0)
044af0d1e6474076366759db86f101778c5f20ccvboxsync RTCpuSetAdd(pSet, idCpu);
044af0d1e6474076366759db86f101778c5f20ccvboxsync return pSet;
044af0d1e6474076366759db86f101778c5f20ccvboxsync}
044af0d1e6474076366759db86f101778c5f20ccvboxsync
044af0d1e6474076366759db86f101778c5f20ccvboxsync
044af0d1e6474076366759db86f101778c5f20ccvboxsyncRTDECL(RTCPUID) RTMpGetCount(void)
044af0d1e6474076366759db86f101778c5f20ccvboxsync{
044af0d1e6474076366759db86f101778c5f20ccvboxsync SYSTEM_INFO SysInfo;
044af0d1e6474076366759db86f101778c5f20ccvboxsync GetSystemInfo(&SysInfo);
044af0d1e6474076366759db86f101778c5f20ccvboxsync Assert((RTCPUID)SysInfo.dwNumberOfProcessors == SysInfo.dwNumberOfProcessors);
044af0d1e6474076366759db86f101778c5f20ccvboxsync return SysInfo.dwNumberOfProcessors;
044af0d1e6474076366759db86f101778c5f20ccvboxsync}
044af0d1e6474076366759db86f101778c5f20ccvboxsync
044af0d1e6474076366759db86f101778c5f20ccvboxsync
044af0d1e6474076366759db86f101778c5f20ccvboxsyncRTDECL(PRTCPUSET) RTMpGetOnlineSet(PRTCPUSET pSet)
044af0d1e6474076366759db86f101778c5f20ccvboxsync{
044af0d1e6474076366759db86f101778c5f20ccvboxsync SYSTEM_INFO SysInfo;
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync GetSystemInfo(&SysInfo);
044af0d1e6474076366759db86f101778c5f20ccvboxsync return RTCpuSetFromU64(pSet, SysInfo.dwActiveProcessorMask);
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync}
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsyncRTDECL(RTCPUID) RTMpGetOnlineCount(void)
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync{
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync RTCPUSET Set;
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync RTMpGetOnlineSet(&Set);
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync return RTCpuSetCount(&Set);
ca3da10d05961c339b5180fbd40a54587d6bad35vboxsync}
3a4a6501d0ccd629d9951b644d380c7bb2d46086vboxsync
044af0d1e6474076366759db86f101778c5f20ccvboxsync