I was just following up on my previous reply and was puzzled by the implementation of 
this fn.

XMLPlatformUtils::compareAndSwap(       void**      toFill
                                , const void* const newValue
                                , const void* const toCompare)
{
#if defined WIN64
    return ::InterlockedCompareExchangePointer(toFill, (void*)newValue, 
(void*)toCompare);
#else

    //
    //  InterlockedCompareExchange is only supported on Windows 98,
    //  Windows NT 4.0, and newer -- not on Windows 95...
    //  If you are willing to give up Win95 support change this to #if 0
    //  otherwise we are back to using assembler.
    //  (But only if building with compilers that support inline assembler.)
    //
    #if defined(_MSC_VER) || defined(__BCPLUSPLUS__)

    void*   result;
    __asm
    {
        mov             eax, toCompare;
        mov             ebx, newValue;
        mov             ecx, toFill
        lock cmpxchg    [ecx], ebx;
        mov             result, eax;
    }
    return result;

    #else

    //
    //  Note we have to cast off the constness of some of these because
    //  the system APIs are not C++ aware in all cases.
    //

    return (void*) ::InterlockedCompareExchange((LPLONG)toFill, (LONG)newValue, 
(LONG)toCompare);

    #endif

#endif

}

here, the developer has used #if defined(_MSC_VER) to branch to his inline assembly 
code. But _MSC_VER is ALWAYS defined on Most windows versions. So, I guess we would 
always be hitting the assembly code (unless you are using win64). Does someone think 
this if define condition needs modifying ? we may probably want to use _WIN32_WINNT or 
atleast check if _MSC_VER > 1000 or something like that.

-Vinayak

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to