VirtualBox

Changeset 36254 in vbox for trunk/src/VBox/Runtime/generic


Ignore:
Timestamp:
Mar 10, 2011 5:22:08 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
70492
Message:

GIP,++: Lots of CPUs (disabled).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/generic/RTMpGetArraySize-generic.cpp

    r33676 r36254  
    55
    66/*
    7  * Copyright (C) 2010 Oracle Corporation
     7 * Copyright (C) 2010-2011 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3030*******************************************************************************/
    3131#include <iprt/mp.h>
     32#include "internal/iprt.h"
     33
     34#include <iprt/asm.h>
    3235#include <iprt/cpuset.h>
    33 #include "internal/iprt.h"
    3436
    3537
    3638RTDECL(uint32_t) RTMpGetArraySize(void)
    3739{
    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
    4060}
    4161RT_EXPORT_SYMBOL(RTMpGetArraySize);
Note: See TracChangeset for help on using the changeset viewer.

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