- Main Page
- Related Pages
- Data Structures
- Files

- File List
- Globals

# include/atomic.h

Go to the documentation of this file.

    00001
    00041 #ifndef ATOMIC_H_INCLUDED
    00042 #define ATOMIC_H_INCLUDED
    00043
    00044 #include <compiler.h>
    00045 #include <stdint.h>
    00046
    00047 typedef struct {
    00048         uint32_t        value;
    00049 } atomic_t;
    00050
    00051 static inline uint32_t atomic_read(atomic_t *ptr)
    00052 {
    00053         barrier();
    00054         return ptr->value;
    00055 }
    00056
    00057 static inline void atomic_write(atomic_t *ptr, uint32_t value)
    00058 {
    00059         ptr->value = value;
    00060         barrier();
    00061 }
    00062
    00067 static inline atomic_t atomic_add(atomic_t *ptr, uint32_t value)
    00068 {
    00069         atomic_t result;
    00070
    00071         result.value = __sync_add_and_fetch(&ptr->value, value);
    00072         return result;
    00073 }
    00074
    00079 static inline atomic_t atomic_sub(atomic_t *ptr, uint32_t value)
    00080 {
    00081         atomic_t result;
    00082
    00083         result.value = __sync_sub_and_fetch(&ptr->value, value);
    00084         return result;
    00085 }
    00086
    00087 #define atomic_inc(ptr)         atomic_add(ptr, 1)
    00088 #define atomic_dec(ptr)         atomic_sub(ptr, 1)
    00089
    00090 #endif /* ATOMIC_H_INCLUDED */