VirtualBox

source: vbox/trunk/include/iprt/cpuset.h@ 8061

Last change on this file since 8061 was 7361, checked in by vboxsync, 17 years ago

RTCpuSetIsMember returns bool not int.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.7 KB
Line 
1/** @file
2 * innotek Portable Runtime - CPU Set.
3 */
4
5/*
6 * Copyright (C) 2008 innotek GmbH
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 ___iprt_cpuset_h
27#define ___iprt_cpuset_h
28
29#include <iprt/types.h>
30#include <iprt/mp.h> /* RTMpCpuIdToSetIndex */
31
32
33__BEGIN_DECLS
34
35/** @defgroup grp_rt_mp RTCpuSet - CPU Set
36 * @ingroup grp_rt
37 * @{
38 */
39
40/**
41 * The maximum number of CPUs a set can contain and IPRT is able
42 * to reference.
43 * @remarks This is the maximum value of the supported platforms.
44 */
45#define RTCPUSET_MAX_CPUS 64
46
47/**
48 * Clear all CPUs.
49 *
50 * @returns pSet.
51 * @param pSet Pointer to the set.
52 */
53DECLINLINE(PRTCPUSET) RTCpuSetEmpty(PRTCPUSET pSet)
54{
55 *pSet = 0;
56 return pSet;
57}
58
59
60/**
61 * Set all CPUs.
62 *
63 * @returns pSet.
64 * @param pSet Pointer to the set.
65 */
66DECLINLINE(PRTCPUSET) RTCpuSetFill(PRTCPUSET pSet)
67{
68 *pSet = UINT64_MAX;
69 return pSet;
70}
71
72
73/**
74 * Adds a CPU given by it's identifier to the set.
75 *
76 * @returns 0 on success, -1 if idCpu isn't valid.
77 * @param pSet Pointer to the set.
78 * @param idCpu The identifier of the CPU to add.
79 */
80DECLINLINE(int) RTCpuSetAdd(PRTCPUSET pSet, RTCPUID idCpu)
81{
82 int iCpu = RTMpCpuIdToSetIndex(idCpu);
83 if (RT_UNLIKELY(iCpu < 0))
84 return -1;
85 *pSet |= RT_BIT_64(iCpu);
86 return 0;
87}
88
89
90/**
91 * Removes a CPU given by it's identifier from the set.
92 *
93 * @returns 0 on success, -1 if idCpu isn't valid.
94 * @param pSet Pointer to the set.
95 * @param idCpu The identifier of the CPU to delete.
96 */
97DECLINLINE(int) RTCpuSetDel(PRTCPUSET pSet, RTCPUID idCpu)
98{
99 int iCpu = RTMpCpuIdToSetIndex(idCpu);
100 if (RT_UNLIKELY(iCpu < 0))
101 return -1;
102 *pSet &= ~RT_BIT_64(iCpu);
103 return 0;
104}
105
106
107/**
108 * Checks if a CPU given by it's identifier is a member of the set.
109 *
110 * @returns true / false accordingly.
111 * @param pSet Pointer to the set.
112 * @param idCpu The identifier of the CPU to look for.
113 */
114DECLINLINE(bool) RTCpuSetIsMember(PCRTCPUSET pSet, RTCPUID idCpu)
115{
116 int iCpu = RTMpCpuIdToSetIndex(idCpu);
117 if (RT_UNLIKELY(iCpu < 0))
118 return false;
119 return !!(*pSet & RT_BIT_64(iCpu));
120}
121
122
123/**
124 * Converts the CPU set to a 64-bit mask.
125 *
126 * @returns The mask.
127 * @param pSet Pointer to the set.
128 */
129DECLINLINE(uint64_t) RTCpuSetToU64(PCRTCPUSET pSet)
130{
131 return *pSet;
132}
133
134
135/**
136 * Initializes the CPU set from a 64-bit mask.
137 *
138 * @param pSet Pointer to the set.
139 * @param fMask The mask.
140 */
141DECLINLINE(PRTCPUSET) RTCpuSetFromU64(PRTCPUSET pSet, uint64_t fMask)
142{
143 *pSet = fMask;
144 return pSet;
145}
146
147
148/**
149 * Count the CPUs in the set.
150 *
151 * @returns CPU count.
152 * @param pSet Pointer to the set.
153 */
154DECLINLINE(RTCPUID) RTCpuSetCount(PRTCPUSET pSet)
155{
156 RTCPUID cCpus = 0;
157 RTCPUID iCpu = 64;
158 while (iCpu-- > 0)
159 if (*pSet & RT_BIT_64(iCpu))
160 cCpus++;
161 return cCpus;
162}
163
164
165/** @} */
166
167__END_DECLS
168
169#endif
170
171
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