On 5/7/07, Erik Mouw <mouw@xxxxxxxxxxxx> wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Mon, May 07, 2007 at 09:25:02PM +0530, Linux Learner wrote: > Is following code SMP safe? > > #define InterlockedIncrement(x) ({ asm volatile ("lock; incl %0" : : > "m" (*x) ); }) > #define InterlockedDecrement(x) ({ asm volatile ("lock; decl %0" : : > "m" (*x) ); }) Why are you reinventing the wheel? The kernel has a couple of well tested and debugged locking primitives with the additional benefit that they also work on non-x86 architectures. > Does -O2 affect SMP safeness of above code? They're not safe with any optimisation level because the compiler is free to reorder instructions around your own lock. Use the kernel supplied locking primitives.
Eric, but the lock primitive acts as a memory barrier , isn't it? AFAIK gcc still optimises the code even if it encounters a volatile after asm but that may be the case when gcc is absolutely sure that the code inside is unreachable. Isn't it? Will this optimization effect the memory barrier act of the lock prefix here? Please CMIIW Thank you ~psr
Erik - -- They're all fools. Don't worry. Darwin may be slow, but he'll eventually get them. -- Matthew Lammers in alt.sysadmin.recovery -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFGP0+b/PlVHJtIto0RAsWKAJ9FSBcBt57/1DZyVsIFNwPZsE0M/gCeIZyb b1A9ZRhwTKS9T+iOqInuYxU= =Ayl+ -----END PGP SIGNATURE----- -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ
-- play the game -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ