__bts -- Test and Set a Bit

Format

#include <builtin.h>
unsigned int __bts(unsigned int *pBits, unsigned int bit)

Language Level: None
Tests and sets a bit within a 4 byte memory operand. The address of the memory operand is pBits and the bit number is bit. Bits are numbered 0 through 31 with 0 being the least significant bit. The test and set operation is only atomic on uni-processor machines.

Return Value
The original value of the selected bit is returned as an unsigned integer.

Example
This example tests and sets bit 4 in an unsigned integer.

#include <stdio.h>
#include <builtin.h>
unsigned int mem = 0xFFFFFFEF;
int main(void)
{
   if (!__bts(&mem, 4))
   {
      printf("Bit 4 should now be one.\n");
   }
   printf("mem = %.8x\n", mem);
   /*****************************************
      The output should be:
      Bit 4 should now be one.
      mem = FFFFFFFF
    ****************************************/
   return 0;
}


__btr -- Test and Reset a Bit
__smp_btr -- Bit Test and Reset Atomically
__smp_bts -- Bit Test and Set Atomically