-
Notifications
You must be signed in to change notification settings - Fork 1
Synchronization methods
Rafael do Nascimento Pereira edited this page Feb 28, 2015
·
9 revisions
This document is a draft.
As the name says, it provides instructions the execute atomically over integers, in other words, without any interruption. The atomic_t
type is defined in inlcude/linux/types.h
The table bellow lists the Atomic Integer Methods:
Atomic Integer Operation | Description |
---|---|
ATOMIC_INIT(int i) | At declaration, initialize to i. |
int atomic_read(atomic_t *v) | Atomically read the integer value of v. |
void atomic_set(atomic_t *v, int i) | Atomically set v equal to i. |
void atomic_add(int i, atomic_t *v) | Atomically add i to v. |
void atomic_sub(int i, atomic_t *v) | Atomically subtract i from v. |
void atomic_inc(atomic_t *v) | Atomically add one to v. |
void atomic_dec(atomic_t *v) | Atomically subtract one from v. |
int atomic_sub_and_test(int i, atomic_t *v) | Atomically subtract i from v and return true if the result is zero; otherwise false. |
int atomic_add_negative(int i, atomic_t *v) | Atomically add i to v and return true if the result is negative; otherwise false. |
int atomic_add_return(int i, atomic_t *v) | Atomically add i to v and return the result. |
int atomic_sub_return(int i, atomic_t *v) | Atomically subtract i from v and return the result. |
int atomic_inc_return(int i, atomic_t *v) | Atomically increment v by one and return the result. |
int atomic_dec_return(int i, atomic_t *v) | Atomically decrement v by one and return the result. |
int atomic_dec_and_test(atomic_t *v) | Atomically decrement v by one and return true if zero; false otherwise. |
int atomic_inc_and_test(atomic_t *v) | Atomically increment v by one and return true if the result is zero; false otherwise. |
Theses methos are define in include/asm-generic/atomic.h
for 32 bit integers. In include/asm-generic/atomic64.h
one can find a 64 bit generic implementation, that can be used in 32 bit processors as well.
Semaphores should be avoided in new code, instead use mutexes.