-----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. 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