|
Threads-Devel : |
From: Anthony Williams (anthony_at_[hidden])
Date: 2006-04-04 12:47:48
Roland Schwarz <roland.schwarz_at_[hidden]> writes:
> Anthony Williams wrote:
>> I'm inclined to think that this is a bug in the Platform SDK, rather than in
>> Boost, since there's nothing in the docs that says you can't take the address
>> of the function.
> I suspect this is not a function at all. Did you try to look at the
> assembly level?
InterlockedCompareExchange is genuinely a function in the win32 Platform
SDK. If you want to use the compiler intrinsics, you have to enable them
manually (as per boost/detail/interlocked.hpp). In 64-bit code, the intrinsics
are enabled by default.
For 32-bit code, the InterlockedCompareExchange intrinsic compiles down to a
few assembly instructions --- a couple of register moves to set up the
operands, and then "lock cmpxchg" to actually do the work.
The ice_wrapper stuff actually can't use the intrinsics even when they are
enabled, since it calls through a function pointer, and this is the problem
for 64-bit compilers --- these functions exist *only* as intrinsics, and not
as callable functions.
>> Anyway, the fix does indeed seem to be to replace the ice_wrapper stuff with a
>> direct call to InterlockedCompareExchange.
> Can't you possibly make use of what is already in
> boost/detail/interlocked.hpp ? I.e. essentially what you are proposing,
> but hopefully already tested.
boost/detail/interlocked.hpp primarily exists to allow the use of the
InterlockedXXX functions without including windows.h --- when this is
available, it uses that rather than declaring the functions directly.
This is actually unfortunate, since windows.h doesn't declare the intrinsics,
but that's irrelevant here.
Anyway, the current once.cpp *does* include windows.h, so we can just use
InterlockedCompareExchange as-is in the source code. From looking at the
workarounds, it appears this function has a different signature on different
compilers, though. Maybe we therefore need to use BOOST_WORKAROUND to deal
with this.
Anthony
-- Anthony Williams Software Developer Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk