Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <assert.h>
- #include <rtapi_bitops.h>
- #define _BIT(nr) (1UL << (nr))
- #define jep_test_and_set_bit(bit, value) \
- (__sync_fetch_and_or(value, _BIT(bit)) & _BIT(bit))
- #define mah_test_and_set_bit(bit, value) __sync_fetch_and_or(value, _BIT(bit))
- int main()
- {
- long x = 1;
- int y = test_and_set_bit(31, &x);
- assert(!y);
- y = test_and_set_bit(31, &x);
- assert(y);
- x = 1;
- y = jep_test_and_set_bit(31, &x);
- assert(!y);
- y = jep_test_and_set_bit(31, &x);
- assert(y);
- x = 1;
- y = mah_test_and_set_bit(31, &x);
- assert(!y);
- y = mah_test_and_set_bit(31, &x);
- assert(y);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement