Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uint16_t AtomicExchange(uint16_t *a, uint16_t new_val) {
- // InterlockedExchange16 seems unavailable on some MSVS installations.
- // Everybody stand back, I pretend to know inline assembly!
- // FIXME: I assume VC is smart enough to save/restore eax/ecx?
- #ifdef _MSC_VER
- __asm {
- mov eax, a
- mov cx, new_val
- xchg [eax], cx ; NOLINT
- mov new_val, cx
- }
- #else
- __asm__("xchgw %[new_val], %[a]" : [new_val] "+r" (new_val) : [a] "m" (*a) : "memory");
- #endif
- return new_val;
- }
Add Comment
Please, Sign In to add comment