VirtualBox

Changeset 30112 in vbox for trunk/include


Ignore:
Timestamp:
Jun 9, 2010 12:31:50 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
62507
Message:

iprt/asm.h,*: Added ASMAtomicWriteNullPtr and ASMAtomicUoWriteNullPtr to better deal with NULL being 0 in C++.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/asm.h

    r30111 r30112  
    24162416 * Atomically writes a pointer value, ordered.
    24172417 *
    2418  * @returns Current *pv value
    24192418 * @param   ppv     Pointer to the pointer variable.
    24202419 * @param   pv      The pointer value to assign to *ppv.
     
    24332432
    24342433/**
    2435  * Convenience macro for avoiding the annoying casting with ASMAtomicWritePtr.
    2436  *
    2437  * @returns Current *pv value
     2434 * Atomically writes a pointer value, ordered.
     2435 *
    24382436 * @param   ppv     Pointer to the pointer variable.
    2439  * @param   pv      The pointer value to assign to *ppv. If NULL, you may have
    2440  *                  to cast it to the right pointer type for GCC to be happy.
     2437 * @param   pv      The pointer value to assign to *ppv. If NULL use
     2438 *                  ASMAtomicWriteNullPtr or you'll land in trouble.
    24412439 *
    24422440 * @remarks This is relatively type safe on GCC platforms when @a pv isn't
     
    24702468
    24712469/**
    2472  * Convenience macro for avoiding the annoying casting involved when using
    2473  * ASMAtomicWritePtr.
     2470 * Atomically sets a pointer to NULL, ordered.
     2471 *
     2472 * @param   ppv     Pointer to the pointer variable that should be set to NULL.
     2473 *
     2474 * @remarks This is relatively type safe on GCC platforms.
     2475 */
     2476#ifdef __GNUC__
     2477# define ASMAtomicWriteNullPtr(ppv) \
     2478    do \
     2479    { \
     2480        __typeof__(*(ppv)) volatile * const ppvTypeChecked = (ppv); \
     2481        AssertCompile(sizeof(*ppv) == sizeof(void *)); \
     2482        Assert(!( (uintptr_t)ppv & ((ARCH_BITS / 8) - 1) )); \
     2483        ASMAtomicWritePtrVoid((void * volatile *)(ppvTypeChecked), NULL); \
     2484    } while (0)
     2485#else
     2486# define ASMAtomicWriteNullPtr(ppv) \
     2487    do \
     2488    { \
     2489        AssertCompile(sizeof(*ppv) == sizeof(void *)); \
     2490        Assert(!( (uintptr_t)ppv & ((ARCH_BITS / 8) - 1) )); \
     2491        ASMAtomicWritePtrVoid((void * volatile *)(ppv), NULL); \
     2492    } while (0)
     2493#endif
     2494
     2495
     2496/**
     2497 * Atomically writes a pointer value, unordered.
    24742498 *
    24752499 * @returns Current *pv value
    24762500 * @param   ppv     Pointer to the pointer variable.
    2477  * @param   pv      The pointer value to assign to *ppv.
     2501 * @param   pv      The pointer value to assign to *ppv. If NULL use
     2502 *                  ASMAtomicUoWriteNullPtr or you'll land in trouble.
    24782503 *
    24792504 * @remarks This is relatively type safe on GCC platforms when @a pv isn't
     
    25012526        Assert(!( (uintptr_t)ppv & ((ARCH_BITS / 8) - 1) )); \
    25022527        *(ppv) = pv; \
     2528    } while (0)
     2529#endif
     2530
     2531
     2532/**
     2533 * Atomically sets a pointer to NULL, unordered.
     2534 *
     2535 * @param   ppv     Pointer to the pointer variable that should be set to NULL.
     2536 *
     2537 * @remarks This is relatively type safe on GCC platforms.
     2538 */
     2539#ifdef __GNUC__
     2540# define ASMAtomicUoWriteNullPtr(ppv) \
     2541    do \
     2542    { \
     2543        __typeof__(*(ppv)) volatile * const ppvTypeChecked = (ppv); \
     2544        AssertCompile(sizeof(*ppv) == sizeof(void *)); \
     2545        Assert(!( (uintptr_t)ppv & ((ARCH_BITS / 8) - 1) )); \
     2546        *(ppvTypeChecked) = NULL; \
     2547    } while (0)
     2548#else
     2549# define ASMAtomicUoWriteNullPtr(ppv) \
     2550    do \
     2551    { \
     2552        AssertCompile(sizeof(*ppv) == sizeof(void *)); \
     2553        Assert(!( (uintptr_t)ppv & ((ARCH_BITS / 8) - 1) )); \
     2554        *(ppv) = NULL; \
    25032555    } while (0)
    25042556#endif
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