Typedef struct {int counter;} atomic_t; # ifdef config_64bittypedef struct {long counter;} atomic64_t; # endif
The Linux kernel uses the Special Data Type atomic_t instead of the integer type that uses the C language directly, which is due to the following reasons:
(1) The atomic_t function only accepts the atomic_t type.
(2) Using the atomic_t type can avoid Compiler Optimization. Atomic operations are very important to using the correct memory address.
(3) The CPU architecture can be avoided.
There is a problem here, why can we avoid the cause by using struct? (2) the compiler is not optimized,
Google.
GCC does not reorder the elements of a struct, because that wowould violate the C standard. section 6.7.2.1 of the c99 standard states:
Within a structure object, the non-bit-memory eld members and the units in which bit-memory ELDS reside have addresses that increase in the order in which they are declared.