vmcpuset.h revision e6e8fc31be238a3370495a3e4fb69dbf41cfffb9
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync * VirtualBox - VMCPUSET Operation.
e6e8fc31be238a3370495a3e4fb69dbf41cfffb9vboxsync * Copyright (C) 2006-2015 Oracle Corporation
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync * available from http://www.virtualbox.org. This file is free software;
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync * you can redistribute it and/or modify it under the terms of the GNU
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync * General Public License (GPL) as published by the Free Software
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync * The contents of this file may alternatively be used under the terms
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync * of the Common Development and Distribution License Version 1.0
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync * VirtualBox OSE distribution, in which case the provisions of the
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync * CDDL are applicable instead of those of the GPL.
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync * You may elect to license modified versions of this file under the
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync * terms and conditions of either the GPL or the CDDL or both.
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync/** @defgroup grp_vmcpuset VMCPUSET Operations
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync * @ingroup grp_types_both
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync * @sa VMCPUSET
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync/** Tests if a valid CPU ID is present in the set.. */
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync#define VMCPUSET_IS_PRESENT(pSet, idCpu) ASMBitTest( &(pSet)->au32Bitmap[0], (idCpu))
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync/** Adds a CPU to the set. */
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync#define VMCPUSET_ADD(pSet, idCpu) ASMBitSet( &(pSet)->au32Bitmap[0], (idCpu))
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync/** Deletes a CPU from the set. */
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync#define VMCPUSET_DEL(pSet, idCpu) ASMBitClear(&(pSet)->au32Bitmap[0], (idCpu))
e6e8fc31be238a3370495a3e4fb69dbf41cfffb9vboxsync/** Adds a CPU to the set, atomically. */
e6e8fc31be238a3370495a3e4fb69dbf41cfffb9vboxsync#define VMCPUSET_ATOMIC_ADD(pSet, idCpu) ASMAtomicBitSet( &(pSet)->au32Bitmap[0], (idCpu))
e6e8fc31be238a3370495a3e4fb69dbf41cfffb9vboxsync/** Deletes a CPU from the set, atomically. */
e6e8fc31be238a3370495a3e4fb69dbf41cfffb9vboxsync#define VMCPUSET_ATOMIC_DEL(pSet, idCpu) ASMAtomicBitClear(&(pSet)->au32Bitmap[0], (idCpu))
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync/** Empties the set. */
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync#define VMCPUSET_EMPTY(pSet) memset(&(pSet)->au32Bitmap[0], '\0', sizeof((pSet)->au32Bitmap))
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync/** Fills the set. */
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync#define VMCPUSET_FILL(pSet) memset(&(pSet)->au32Bitmap[0], 0xff, sizeof((pSet)->au32Bitmap))
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync/** Checks if two sets are equal to one another. */
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync#define VMCPUSET_IS_EQUAL(pSet1, pSet2) (memcmp(&(pSet1)->au32Bitmap[0], &(pSet2)->au32Bitmap[0], sizeof((pSet1)->au32Bitmap)) == 0)
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync/** Checks if the set is empty. */
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync#define VMCPUSET_IS_EMPTY(a_pSet) ( (a_pSet)->au32Bitmap[0] == 0 \
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync/** Finds the first CPU present in the SET.
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync * @returns CPU index if found, NIL_VMCPUID if not. */
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync#define VMCPUSET_FIND_FIRST_PRESENT(a_pSet) VMCpuSetFindFirstPresentInternal(a_pSet)
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync/** Implements VMCPUSET_FIND_FIRST_PRESENT.
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync * @returns CPU index of the first CPU present in the set, NIL_VMCPUID if none
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync * are present.
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync * @param pSet The set to scan.
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsyncDECLINLINE(int32_t) VMCpuSetFindFirstPresentInternal(PCVMCPUSET pSet)
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync int i = ASMBitFirstSet(&pSet->au32Bitmap[0], RT_ELEMENTS(pSet->au32Bitmap) * 32);
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync/** Finds the first CPU present in the SET.
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync * @returns CPU index if found, NIL_VMCPUID if not. */
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync#define VMCPUSET_FIND_LAST_PRESENT(a_pSet) VMCpuSetFindLastPresentInternal(a_pSet)
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync/** Implements VMCPUSET_FIND_LAST_PRESENT.
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync * @returns CPU index of the last CPU present in the set, NIL_VMCPUID if none
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync * are present.
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync * @param pSet The set to scan.
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsyncDECLINLINE(int32_t) VMCpuSetFindLastPresentInternal(PCVMCPUSET pSet)
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync while (i-- > 0)
5835c306f653aa74c80f79f84a32451fe0ba37c0vboxsync u |= i << 5;