Skip to main content.

5.7.4.1. Atomic operations

example:

initalize:

atomic_t counter ATOMIC_INIT(0); /* or */
atomic_set(&counter, 0);

use:

atomic_add(3, &counter);
atomic_inc(&counter);
atomic_sub(2, &counter);
atomic_dec(&counter);
val = atomic_read(&counter);

operate and test:

if (atomic_sub_and_test(1, &counter) {
        printk(KERN_INFO "counter is zero!\n");
}

...

5.7.4. Concurrency and Race Conditions 1. Denx Training Topics 5.7.4.2. Mutexes
Prev Home Next