972
edits
[unchecked revision] | [unchecked revision] |
m (Bot: Replace deprecated source tag with syntaxhighlight) |
m (Bot: Replace deprecated source tag with syntaxhighlight) |
||
Line 168:
One example where this can be useful, is the CMPXCHG instruction (see [http://en.wikipedia.org/wiki/Compare-and-swap Compare and Swap]), which the Linux kernel source code defines as follows:
<
/* TODO: You should use modern GCC atomic instruction builtins instead of this. */
#include <stdint.h>
Line 181:
__ret; \
}
</syntaxhighlight>
In addition to returning the current value in EAX, CMPXCHG sets the zero flag (Z) when successful. Without asm gotos, your code will have to check the returned value;
this CMP instruction can be avoided as follows:
<
/* TODO: You should use modern GCC atomic instruction builtins instead of this. */
// Works for both 32 and 64 bit
Line 199:
: fail_label ); \
}
</syntaxhighlight>
This new macro could then be used as follows:
|