VirtualBox

Changeset 37316 in vbox for trunk/include


Ignore:
Timestamp:
Jun 3, 2011 12:49:02 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
72071
Message:

IPRT: Inlined the already-done check in RTOnce().

Location:
trunk/include/iprt
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/include/iprt/mangling.h

    r37234 r37316  
    847847# define RTNetTCPChecksum                               RT_MANGLER(RTNetTCPChecksum)
    848848# define RTNetUDPChecksum                               RT_MANGLER(RTNetUDPChecksum)
    849 # define RTOnce                                         RT_MANGLER(RTOnce)
     849# define RTOnceSlow                                     RT_MANGLER(RTOnceSlow)
    850850# define RTOnceReset                                    RT_MANGLER(RTOnceReset)
    851851# define RTPathAbs                                      RT_MANGLER(RTPathAbs)
  • TabularUnified trunk/include/iprt/once.h

    r33262 r37316  
    2929#include <iprt/cdefs.h>
    3030#include <iprt/types.h>
     31#include <iprt/asm.h>
    3132#include <iprt/err.h>
    3233
     
    120121 * @param   pvUser2         The second user parameter for pfnOnce.
    121122 */
    122 RTDECL(int) RTOnce(PRTONCE pOnce, PFNRTONCE pfnOnce, void *pvUser1, void *pvUser2);
     123RTDECL(int) RTOnceSlow(PRTONCE pOnce, PFNRTONCE pfnOnce, void *pvUser1, void *pvUser2);
     124
     125/**
     126 * Serializes execution of the pfnOnce function, making sure it's
     127 * executed exactly once and that nobody returns from RTOnce before
     128 * it has executed successfully.
     129 *
     130 * @returns IPRT like status code returned by pfnOnce.
     131 *
     132 * @param   pOnce           Pointer to the execute once variable.
     133 * @param   pfnOnce         The function to executed once.
     134 * @param   pvUser1         The first user parameter for pfnOnce.
     135 * @param   pvUser2         The second user parameter for pfnOnce.
     136 */
     137DECLINLINE(int) RTOnce(PRTONCE pOnce, PFNRTONCE pfnOnce, void *pvUser1, void *pvUser2)
     138{
     139    int32_t iState = ASMAtomicUoReadS32(&pOnce->iState);
     140    if (RT_LIKELY(   iState == RTONCESTATE_DONE
     141                  || iState == RTONCESTATE_DONE_CREATING_SEM
     142                  || iState == RTONCESTATE_DONE_HAVE_SEM ))
     143        return ASMAtomicUoReadS32(&pOnce->rc);
     144    return RTOnceSlow(pOnce, pfnOnce, pvUser1, pvUser2);
     145}
    123146
    124147/**
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