Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

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

Don_Burn_1Don_Burn_1 Member Posts: 4,311
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<<bit));
}

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
>

Comments

  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    > 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
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
Writing WDF Drivers 25 Feb 2019 OSR Seminar Space
Developing Minifilters 8 April 2019 OSR Seminar Space