Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Fetch and increment with modulo wrap
- * Although there's theoretically a race condition,
- * it's practically impossible to increment 32^2 times
- * while the number is wrapped */
- static inline uint64_t atomic_fetch_inc_modulo_wrap(atomic_uint_fast64_t *val,
- uint32_t wrap) {
- uint64_t fetched = (*val)++;
- uint32_t hi = (fetched & 0xFFFFFFFF00000000) >> 32;
- if (hi == wrap) {
- atomic_fetch_and(val, 0xFFFFFFFF);
- }
- return fetched % wrap;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement