Changeset 36254 in vbox for trunk/src/VBox/Runtime/generic
- Timestamp:
- Mar 10, 2011 5:22:08 PM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 70492
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/generic/RTMpGetArraySize-generic.cpp
r33676 r36254 5 5 6 6 /* 7 * Copyright (C) 2010 Oracle Corporation7 * Copyright (C) 2010-2011 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 30 30 *******************************************************************************/ 31 31 #include <iprt/mp.h> 32 #include "internal/iprt.h" 33 34 #include <iprt/asm.h> 32 35 #include <iprt/cpuset.h> 33 #include "internal/iprt.h"34 36 35 37 36 38 RTDECL(uint32_t) RTMpGetArraySize(void) 37 39 { 38 RTCPUSET CpuSet; 39 return RTCpuLastIndex(RTMpGetSet(&CpuSet)) + 1; 40 /* 41 * Cache the result here. This whole point of this function is that it 42 * will always return the same value, so that should be safe. 43 * 44 * Note! Because RTCPUSET may be to small to represent all the CPUs, we 45 * check with RTMpGetCount() as well. 46 */ 47 static uint32_t s_cMaxCpus = 0; 48 uint32_t cCpus = s_cMaxCpus; 49 if (RT_UNLIKELY(cCpus == 0)) 50 { 51 RTCPUSET CpuSet; 52 uint32_t cCpus1 = RTCpuLastIndex(RTMpGetSet(&CpuSet)) + 1; 53 uint32_t cCpus2 = RTMpGetCount(); 54 uint32_t cCpus = RT_MAX(cCpus1, cCpus2); 55 ASMAtomicCmpXchgU32(&s_cMaxCpus, cCpus, 0); 56 return cCpus; 57 } 58 return s_cMaxCpus; 59 40 60 } 41 61 RT_EXPORT_SYMBOL(RTMpGetArraySize);
Note:
See TracChangeset
for help on using the changeset viewer.