RE: How to performs an atomic operation that clear the specified bit in

You don’t need two Interlocked operations the first one is on a local
variable. Also, you are taking a pointer to the pointer. Finally your
arguments for the shift are reversed.

API_AtomicClearBit(LONG volatile *Destination, INT32 bit)
{
InterlockedAnd( Destination, (0xffffffff^(1<}

Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

> -----Original Message-----
> From: xxxxx@yahoo.com.cn [mailto:xxxxx@yahoo.com.cn]
> Posted At: Tuesday, May 04, 2010 10:24 AM
> Posted To: ntdev
> Conversation: How to performs an atomic operation that clear the
specified bit
> in INT32 value?
> Subject: How to performs an atomic operation that clear the specified
bit in
> INT32 value?
>
> My SDK API:
>
> API_AtomicClearBit(INT32 *Destination, INT32 bit)
> {
> …
> }
>
> func()
> {
> INT32 value = 0x4567;
> …
> API_AtomicClearBit(&value,2);
> }
>
> I want to clear second bit of the value 0x4567 by atomic operation ,
what
> shall I do?
> The below is my test code, but I think it is wrong:
>
> API_AtomicClearBit(INT32 *Destination, INT32 bit)
> {
> INT32 oldValue = 0xFFFF;
> InterlockedXor((volatile long *)(&oldValue),(bit<<1));
> InterlockedAnd((volatile unsigned long *)Destination,oldValue); }
>
>
>
> Information from ESET Smart Security, version of virus
signature
> database 5085 (20100504)

>
> The message was checked by ESET Smart Security.
>
> http://www.eset.com
>

> I want to clear second bit of the value 0x4567

API_AtomicClearBit(&value,2);

Just for info: this will clear the third bit, not the second bit:
(1<<0)==0x0001, (1<<1)==0x0002, (i<<2)==0x0004