Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <assert.h>
  2. #include <rtapi_bitops.h>
  3.  
  4. #define _BIT(nr) (1UL << (nr))
  5.  
  6. #define jep_test_and_set_bit(bit, value) \
  7. (__sync_fetch_and_or(value, _BIT(bit)) & _BIT(bit))
  8. #define mah_test_and_set_bit(bit, value) __sync_fetch_and_or(value, _BIT(bit))
  9.  
  10. int main()
  11. {
  12. long x = 1;
  13. int y = test_and_set_bit(31, &x);
  14. assert(!y);
  15. y = test_and_set_bit(31, &x);
  16. assert(y);
  17.  
  18. x = 1;
  19. y = jep_test_and_set_bit(31, &x);
  20. assert(!y);
  21. y = jep_test_and_set_bit(31, &x);
  22. assert(y);
  23.  
  24. x = 1;
  25. y = mah_test_and_set_bit(31, &x);
  26. assert(!y);
  27. y = mah_test_and_set_bit(31, &x);
  28. assert(y);
  29.  
  30. return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement