x86/atomic.c File Reference

#include <SysThread.h>

Defines

#define SYSATOMICADD32(locationP, addvalue)
#define SYSATOMICAND32(locationP, andvalue)
#define SYSATOMICCMPXCHG32(locationP, oldvalue, newvalue)
#define SYSATOMICDEC32(locationP)   SYSATOMICADD32(locationP,-1)
#define SYSATOMICINC32(locationP)   SYSATOMICADD32(locationP,1)
#define SYSATOMICOR32(locationP, orvalue)
#define SYSATOMICSUB32(locationP, subvalue)

Functions

int32_t SysAtomicAdd32 (volatile int32_t *location, int32_t addvalue)
uint32_t SysAtomicAnd32 (volatile uint32_t *location, uint32_t andvalue)
uint32_t SysAtomicCompareAndSwap32 (volatile uint32_t *location, uint32_t oldvalue, uint32_t newvalue)
int32_t SysAtomicDec32 (volatile int32_t *location)
int32_t SysAtomicInc32 (volatile int32_t *location)
uint32_t SysAtomicOr32 (volatile uint32_t *location, uint32_t orvalue)
int32_t SysAtomicSub32 (volatile int32_t *location, int32_t subvalue)


Define Documentation

#define SYSATOMICADD32 locationP,
addvalue   ) 
 

Value:

({                      \
    int32_t res;                \
    asm volatile                \
    (                   \
        "1:"                \
        "mov %2, %%ecx;"        \
        "mov (%1), %0;"         \
        "add %0, %%ecx;"        \
        "lock; cmpxchg %%ecx, (%1);"    \
        "jnz 1b"            \
        : "=&a"(res)            \
        : "r"(locationP), "r"(addvalue) \
        : "%ecx"            \
    );                  \
    res;                    \
})

#define SYSATOMICAND32 locationP,
andvalue   ) 
 

Value:

({                      \
    uint32_t res;               \
    asm volatile                \
    (                   \
        "1:"                \
        "mov %2, %%ecx;"        \
        "mov (%1), %0;"         \
        "and %0, %%ecx;"        \
        "lock; cmpxchg %%ecx, (%1);"    \
        "jnz 1b"            \
        : "=&a"(res)            \
        : "r"(locationP), "r"(andvalue) \
        : "%ecx"            \
    );                  \
    res;                    \
})

#define SYSATOMICCMPXCHG32 locationP,
oldvalue,
newvalue   ) 
 

Value:

({                              \
    uint32_t success;                   \
    asm volatile                        \
    (                           \
        "lock; cmpxchg %%ecx, (%%edx);"         \
                " sete %%al;"                   \
                " andl $1, %%eax"               \
        : "=a" (success)                \
        : "a" (oldvalue), "c" (newvalue), "d" (location)\
    );                          \
    success;                        \
})

#define SYSATOMICDEC32 locationP   )     SYSATOMICADD32(locationP,-1)
 

#define SYSATOMICINC32 locationP   )     SYSATOMICADD32(locationP,1)
 

#define SYSATOMICOR32 locationP,
orvalue   ) 
 

Value:

({                      \
    uint32_t res;               \
    asm volatile                \
    (                   \
        "1:"                \
        "mov %2, %%ecx;"        \
        "mov (%1), %0;"         \
        "or %0, %%ecx;"         \
        "lock; cmpxchg %%ecx, (%1);"    \
        "jnz 1b"            \
        : "=&a"(res)            \
        : "r"(locationP), "r"(orvalue)  \
        : "%ecx"            \
    );                  \
    res;                    \
})

#define SYSATOMICSUB32 locationP,
subvalue   ) 
 

Value:

({                      \
    int32_t res;                \
    asm volatile                \
    (                   \
        "1:"                \
        "mov %2, %%ecx;"        \
        "mov (%1), %0;"         \
        "sub %0, %%ecx;"        \
        "lock; cmpxchg %%ecx, (%1);"    \
        "jnz 1b"            \
        : "=&a"(res)            \
        : "r"(locationP), "r"(subvalue) \
        : "%ecx"            \
    );                  \
    res;                    \
})


Function Documentation

int32_t SysAtomicAdd32 volatile int32_t *  location,
int32_t  addvalue
 

uint32_t SysAtomicAnd32 volatile uint32_t *  location,
uint32_t  andvalue
 

uint32_t SysAtomicCompareAndSwap32 volatile uint32_t *  location,
uint32_t  oldvalue,
uint32_t  newvalue
 

int32_t SysAtomicDec32 volatile int32_t *  location  ) 
 

int32_t SysAtomicInc32 volatile int32_t *  location  ) 
 

uint32_t SysAtomicOr32 volatile uint32_t *  location,
uint32_t  orvalue
 

int32_t SysAtomicSub32 volatile int32_t *  location,
int32_t  subvalue