Certain operations are guaranteed atomic on all platforms. The
first class of operations work on atomic_t
contains a signed integer (at least 32 bits long), and you must use
these functions to manipulate or read atomic_t variables.
atomic_set() get and set the counter,
true if it was decremented to zero).
Yes. It returns true (i.e. != 0) if the atomic variable is zero.
Note that these functions are slower than normal arithmetic, and so should not be used unnecessarily.
The second class of atomic operations is atomic bit operations on an
unsigned long, defined in
operations generally take a pointer to the bit pattern, and a bit
number: 0 is the least significant bit.
change_bit() set, clear, and flip the
test_and_change_bit() do the same thing,
except return true if the bit was previously set; these are
particularly useful for atomically setting flags.
It is possible to call these operations with bit indices greater than BITS_PER_LONG. The resulting behavior is strange on big-endian platforms though so it is a good idea not to do this.