VirtualBox

source: vbox/trunk/include/VBox/vmm/vmcpuset.h@ 79629

Last change on this file since 79629 was 76585, checked in by vboxsync, 6 years ago

*: scm --fix-header-guard-endif

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.4 KB
Line 
1/** @file
2 * VirtualBox - VMCPUSET Operation.
3 */
4
5/*
6 * Copyright (C) 2006-2019 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef VBOX_INCLUDED_vmm_vmcpuset_h
27#define VBOX_INCLUDED_vmm_vmcpuset_h
28#ifndef RT_WITHOUT_PRAGMA_ONCE
29# pragma once
30#endif
31
32#include <VBox/types.h>
33#include <iprt/asm.h>
34#include <iprt/string.h>
35
36/** @defgroup grp_vmcpuset VMCPUSET Operations
37 * @ingroup grp_types_both
38 * @sa VMCPUSET
39 * @{
40 */
41
42/** Tests if a valid CPU ID is present in the set. */
43#define VMCPUSET_IS_PRESENT(pSet, idCpu) ASMBitTest( &(pSet)->au32Bitmap[0], (idCpu))
44/** Adds a CPU to the set. */
45#define VMCPUSET_ADD(pSet, idCpu) ASMBitSet( &(pSet)->au32Bitmap[0], (idCpu))
46/** Deletes a CPU from the set. */
47#define VMCPUSET_DEL(pSet, idCpu) ASMBitClear(&(pSet)->au32Bitmap[0], (idCpu))
48/** Adds a CPU to the set, atomically. */
49#define VMCPUSET_ATOMIC_ADD(pSet, idCpu) ASMAtomicBitSet( &(pSet)->au32Bitmap[0], (idCpu))
50/** Deletes a CPU from the set, atomically. */
51#define VMCPUSET_ATOMIC_DEL(pSet, idCpu) ASMAtomicBitClear(&(pSet)->au32Bitmap[0], (idCpu))
52/** Empties the set. */
53#define VMCPUSET_EMPTY(pSet) memset(&(pSet)->au32Bitmap[0], '\0', sizeof((pSet)->au32Bitmap))
54/** Fills the set. */
55#define VMCPUSET_FILL(pSet) memset(&(pSet)->au32Bitmap[0], 0xff, sizeof((pSet)->au32Bitmap))
56/** Checks if two sets are equal to one another. */
57#define VMCPUSET_IS_EQUAL(pSet1, pSet2) (memcmp(&(pSet1)->au32Bitmap[0], &(pSet2)->au32Bitmap[0], sizeof((pSet1)->au32Bitmap)) == 0)
58/** Checks if the set is empty. */
59#define VMCPUSET_IS_EMPTY(a_pSet) ( (a_pSet)->au32Bitmap[0] == 0 \
60 && (a_pSet)->au32Bitmap[1] == 0 \
61 && (a_pSet)->au32Bitmap[2] == 0 \
62 && (a_pSet)->au32Bitmap[3] == 0 \
63 && (a_pSet)->au32Bitmap[4] == 0 \
64 && (a_pSet)->au32Bitmap[5] == 0 \
65 && (a_pSet)->au32Bitmap[6] == 0 \
66 && (a_pSet)->au32Bitmap[7] == 0 \
67 )
68/** Finds the first CPU present in the SET.
69 * @returns CPU index if found, NIL_VMCPUID if not. */
70#define VMCPUSET_FIND_FIRST_PRESENT(a_pSet) VMCpuSetFindFirstPresentInternal(a_pSet)
71
72/** Implements VMCPUSET_FIND_FIRST_PRESENT.
73 *
74 * @returns CPU index of the first CPU present in the set, NIL_VMCPUID if none
75 * are present.
76 * @param pSet The set to scan.
77 */
78DECLINLINE(int32_t) VMCpuSetFindFirstPresentInternal(PCVMCPUSET pSet)
79{
80 int i = ASMBitFirstSet(&pSet->au32Bitmap[0], RT_ELEMENTS(pSet->au32Bitmap) * 32);
81 return i >= 0 ? (VMCPUID)i : NIL_VMCPUID;
82}
83
84/** Finds the first CPU present in the SET.
85 * @returns CPU index if found, NIL_VMCPUID if not. */
86#define VMCPUSET_FIND_LAST_PRESENT(a_pSet) VMCpuSetFindLastPresentInternal(a_pSet)
87
88/** Implements VMCPUSET_FIND_LAST_PRESENT.
89 *
90 * @returns CPU index of the last CPU present in the set, NIL_VMCPUID if none
91 * are present.
92 * @param pSet The set to scan.
93 */
94DECLINLINE(int32_t) VMCpuSetFindLastPresentInternal(PCVMCPUSET pSet)
95{
96 uint32_t i = RT_ELEMENTS(pSet->au32Bitmap);
97 while (i-- > 0)
98 {
99 uint32_t u = pSet->au32Bitmap[i];
100 if (u)
101 {
102 u = ASMBitLastSetU32(u);
103 u--;
104 u |= i << 5;
105 return u;
106 }
107 }
108 return NIL_VMCPUID;
109}
110
111/** @} */
112
113#endif /* !VBOX_INCLUDED_vmm_vmcpuset_h */
114
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette