_interlockedbittestandset, _interlockedbittestandset64
Updated: March 2011
Microsoft Specific
Generate the lock bts instruction, which examines bit b of the address a and returns its current value before setting it to 1.
unsigned char _interlockedbittestandset( long *a, long b ); unsigned char _interlockedbittestandset64( __int64 *a, __int64 b );
As a result of the lock bts instruction, the bit is set to 1. The operation is atomic.
These functions behave as read-write memory barriers. For more information, see _ReadWriteBarrier.
This routine is only available as an intrinsic.
Older SDKs have an error
Error 1 error C2733: second C linkage of overloaded function '_interlockedbittestandset' not allowed $VCDIR\include\intrin.h 944This is due to the fact that WinNT.h and intrin.h both declare those functions (set and reset and their 64 bit counterparts). One workaround is this:
Error 2 error C2733: second C linkage of overloaded function '_interlockedbittestandreset' not allowed $VCDIR\include\intrin.h 945
#if _MSC_VER >= 1400
// Following 8 lines: workaround for a bug in some older SDKs
# pragma push_macro("_interlockedbittestandset")
# pragma push_macro("_interlockedbittestandreset")
# pragma push_macro("_interlockedbittestandset64")
# pragma push_macro("_interlockedbittestandreset64")
# define _interlockedbittestandset _local_interlockedbittestandset
# define _interlockedbittestandreset _local_interlockedbittestandreset
# define _interlockedbittestandset64 _local_interlockedbittestandset64
# define _interlockedbittestandreset64 _local_interlockedbittestandreset64
# include <intrin.h> // to force the header not to be included elsewhere
# pragma pop_macro("_interlockedbittestandreset64")
# pragma pop_macro("_interlockedbittestandset64")
# pragma pop_macro("_interlockedbittestandreset")
# pragma pop_macro("_interlockedbittestandset")
#endif
It should be okay to include this before or after WinNT.h.
- 4/25/2012
- Miðgarðsormr