You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by vi...@lightningcast.com on 2003/03/14 17:16:28 UTC

XMLPlatformUtils::compareAndSwap fn

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: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


RE: XMLPlatformUtils::compareAndSwap fn

Posted by Robert Buck <rb...@mathworks.com>.
I think the point we're making is that the call to
InterlockedCompareExchange that is in that code will never happen since the
first part of the #ifdef is always satisfied for all windows platforms
because _MSC_VER is always defined.  I believe Borland even defines it. So
the suggestion would be to drop the InterlockedCompareExchange (not
suggested) or change the _MSC_VER to check version info or some other
variable to detect which os you are compiling on. If you are building with
msvc you ought to be using InterlockedCompareExchange .

> -----Original Message-----
> From: David N Bertoni/Cambridge/IBM [mailto:david_n_bertoni@us.ibm.com]
> Sent: Friday, March 14, 2003 11:37 AM
>
> The whole point of the ifdef is that all Windows builds use the inline
> assembly code.  The ifdef is checked at compile time, but the
> assumption is
> you would want to build on NT or Win2000, but run on Windows 95.

And if you build with MSVC on NT and run on NT you still get the inline
assy.

If you build with MSVC on '95 and run on NT you still get inline assy.

You build with Borland or other compilers you still get the inline assy.

You never get to use InterlockedCompareExchange . That is the whole point.
The call is superfluous.

Bob

>
> Dave
>
>
>
>
>
>
>                       <vinayak@lightni
>
>
>                       ngcast.com>              To:
> <xe...@xml.apache.org>
>
>                                                cc:      (bcc:
> David N Bertoni/Cambridge/IBM)
>
>                       03/14/2003 08:16         Subject:
> XMLPlatformUtils::compareAndSwap fn
>
>                       AM
>
>
>                       Please respond
>
>
>                       to xerces-c-dev
>
>
>
>
>
>
>
>
> I was just following up on my previous reply and was puzzled by the
> implementation of this fn.
>
> ...
>
> 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: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: XMLPlatformUtils::compareAndSwap fn

Posted by David N Bertoni/Cambridge/IBM <da...@us.ibm.com>.



The whole point of the ifdef is that all Windows builds use the inline
assembly code.  The ifdef is checked at compile time, but the assumption is
you would want to build on NT or Win2000, but run on Windows 95.

Dave



                                                                                                                                                 
                      <vinayak@lightni                                                                                                           
                      ngcast.com>              To:      <xe...@xml.apache.org>                                                            
                                               cc:      (bcc: David N Bertoni/Cambridge/IBM)                                                     
                      03/14/2003 08:16         Subject: XMLPlatformUtils::compareAndSwap fn                                                      
                      AM                                                                                                                         
                      Please respond                                                                                                             
                      to xerces-c-dev                                                                                                            
                                                                                                                                                 



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

...

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: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org