On some single processor machines the "++" operation is atomic in all
respects. The atomic_t, atomic_inc etc are primarily there for SMP machines
or systems where it may not be.
On the m68k for example ++ might generate this code if the value is also
referred too later (this is a 'sufficiently contrived example' - gcc's code
generator isnt quite so daft)
MOVE D0, _variable
ADDQ #1, D0
MOVE _variable, D0
With atomic_t it will always generate something like
ADD #1, _variable
On SMP machines it becomes even more 'interesting' because multiple processors
access the bus and same memory. So given the x86 code
inc [_variable]
executed on both processors at once, both may fetch and write the same value
back. So on x86 the atomic_t code generates
lock inc [_variable]
Where lock is an x86 "read-modify-write" instruction - that is one that the
other cpus cannot get at the value while the inc is being done.
Alan
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/