Changeset 36232 in vbox for trunk/include/iprt
- Timestamp:
- Mar 9, 2011 4:41:09 PM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 70453
- Location:
- trunk/include/iprt
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/cpuset.h
r28800 r36232 42 42 * The maximum number of CPUs a set can contain and IPRT is able 43 43 * to reference. 44 * 45 * @remarks Must match the size of RTCPUSET. 44 46 * @remarks This is the maximum value of the supported platforms. 45 47 */ 46 #define RTCPUSET_MAX_CPUS 64 48 #ifdef RT_WITH_LOTS_OF_CPUS 49 # define RTCPUSET_MAX_CPUS 256 50 #else 51 # define RTCPUSET_MAX_CPUS 64 52 #endif 47 53 48 54 /** … … 54 60 DECLINLINE(PRTCPUSET) RTCpuSetEmpty(PRTCPUSET pSet) 55 61 { 62 #ifdef RTCPUSET_IS_BITMAP 63 unsigned i; 64 for (i = 0; i < RT_ELEMENTS(pSet->bmSet); i++) 65 pSet->bmSet[i] = 0; 66 #else 56 67 *pSet = 0; 68 #endif 57 69 return pSet; 58 70 } … … 67 79 DECLINLINE(PRTCPUSET) RTCpuSetFill(PRTCPUSET pSet) 68 80 { 81 #ifdef RTCPUSET_IS_BITMAP 82 unsigned i; 83 for (i = 0; i < RT_ELEMENTS(pSet->bmSet); i++) 84 pSet->bmSet[i] = UINT64_MAX; 85 #else 69 86 *pSet = UINT64_MAX; 87 #endif 70 88 return pSet; 71 89 } … … 167 185 DECLINLINE(bool) RTCpuSetIsEqual(PCRTCPUSET pSet1, PCRTCPUSET pSet2) 168 186 { 187 #ifdef RTCPUSET_IS_BITMAP 188 unsigned i; 189 for (i = 0; i < RT_ELEMENTS(pSet1->bmSet); i++) 190 if (pSet1->bmSet[i] != pSet1->bmSet[i]) 191 return false; 192 return true; 193 #else 169 194 return *pSet1 == *pSet2 ? true : false; 195 #endif 170 196 } 171 197 … … 176 202 * @returns The mask. 177 203 * @param pSet Pointer to the set. 204 * @remarks Use with extreme care as it may lose information! 178 205 */ 179 206 DECLINLINE(uint64_t) RTCpuSetToU64(PCRTCPUSET pSet) 180 207 { 208 #ifdef RTCPUSET_IS_BITMAP 209 return pSet->bmSet[0]; 210 #else 181 211 return *pSet; 212 #endif 182 213 } 183 214 … … 191 222 DECLINLINE(PRTCPUSET) RTCpuSetFromU64(PRTCPUSET pSet, uint64_t fMask) 192 223 { 224 #ifdef RTCPUSET_IS_BITMAP 225 unsigned i; 226 227 pSet->bmSet[0] = fMask; 228 for (i = 1; i < RT_ELEMENTS(pSet->bmSet); i++) 229 pSet->bmSet[i] = 0; 230 #else 193 231 *pSet = fMask; 232 #endif 194 233 return pSet; 195 234 } … … 204 243 DECLINLINE(int) RTCpuSetCount(PCRTCPUSET pSet) 205 244 { 206 int cCpus = 0; 207 RTCPUID iCpu = 64; 245 int cCpus = 0; 246 #ifdef RTCPUSET_IS_BITMAP 247 unsigned i; 248 249 for (i = 0; i < RT_ELEMENTS(pSet->bmSet); i++) 250 { 251 uint64_t u64 = pSet->bmSet[i]; 252 if (u64 != 0) 253 { 254 unsigned iCpu = 64; 255 while (iCpu-- > 0) 256 { 257 if (u64 & 1) 258 cCpus++; 259 u64 >>= 1; 260 } 261 } 262 } 263 264 #else 265 unsigned iCpu = 64; 208 266 while (iCpu-- > 0) 209 267 if (*pSet & RT_BIT_64(iCpu)) 210 268 cCpus++; 269 #endif 211 270 return cCpus; 212 271 } … … 221 280 DECLINLINE(int) RTCpuLastIndex(PCRTCPUSET pSet) 222 281 { 282 #ifdef RTCPUSET_IS_BITMAP 283 unsigned i = RT_ELEMENTS(pSet->bmSet); 284 while (i-- > 0) 285 { 286 uint64_t u64 = pSet->bmSet[i]; 287 if (u64) 288 { 289 /* There are more efficient ways to do this in asm.h... */ 290 unsigned iBit; 291 for (iBit = 63; iBit > 0; iBit--) 292 { 293 if (u64 & RT_BIT_64(63)) 294 break; 295 u64 <<= 1; 296 } 297 return i * 64 + iBit; 298 } 299 } 300 return 0; 301 302 #else 223 303 /* There are more efficient ways to do this in asm.h... */ 224 304 int iCpu = RTCPUSET_MAX_CPUS; … … 227 307 return iCpu; 228 308 return iCpu; 309 #endif 229 310 } 230 311 -
trunk/include/iprt/types.h
r35662 r36232 1672 1672 * Treat this as an opaque type and always use RTCpuSet* for manupulating it. 1673 1673 * @remarks Subject to change. */ 1674 #ifdef RT_WITH_LOTS_OF_CPUS /** @todo RT_WITH_LOTS_OF_CPUS is just a temporary placeholder. */ 1675 typedef struct RTCPUSET 1676 { 1677 /** The bitmap. 1678 * @remarks Must be large enough to hold RTCPUSET_MAX_CPUS bits, see 1679 * iprt/cpuset.h. */ 1680 uint64_t bmSet[256 / 64]; 1681 } RTCPUSET; 1682 /** Indicates that RTCPUSET is a bitmap and not a 64-bit integer. */ 1683 # define RTCPUSET_IS_BITMAP 1 1684 #else 1674 1685 typedef uint64_t RTCPUSET; 1686 #endif 1675 1687 /** Pointer to a CPU set. */ 1676 1688 typedef RTCPUSET *PRTCPUSET;
Note:
See TracChangeset
for help on using the changeset viewer.