PFUNC 1.0
Defines | Functions
pfunc/pfunc_atomics.h File Reference

Implements atomic operations on PODs. More...

#include <pfunc/config.h>
#include <pfunc/environ.hpp>
#include <stdint.h>
#include <pfunc/asm/x86.h>

Go to the source code of this file.

Defines

#define PFUNC_STATIC_CAST(T, expr)   (T)(expr)
#define PFUNC_CONST_CAST(T, expr)   (T)(expr)
#define PFUNC_DYNAMIC_CAST(T, expr)   (T)(expr)
#define PFUNC_REINTERPRET_CAST(T, expr)   (T)(expr)

Functions

static PFUNC_INLINE int8_t pfunc_compare_and_swap_8 (volatile void *dest, int8_t exchg, int8_t comprnd)
 Compare and Swap an 8-bit memory location.
static PFUNC_INLINE int16_t pfunc_compare_and_swap_16 (volatile void *dest, int16_t exchg, int16_t comprnd)
 Compare and Swap an 16-bit memory location.
static PFUNC_INLINE int32_t pfunc_compare_and_swap_32 (volatile void *dest, int32_t exchg, int32_t comprnd)
 Compare and Swap an 32-bit memory location.
static PFUNC_INLINE int8_t pfunc_fetch_and_store_8 (volatile void *location, int8_t new_val)
 Atomically fetches 8-bit value from memory and stores a new value.
static PFUNC_INLINE int16_t pfunc_fetch_and_store_16 (volatile void *location, int16_t new_val)
 Atomically fetches 16-bit value from memory and stores a new value.
static PFUNC_INLINE int32_t pfunc_fetch_and_store_32 (volatile void *location, int32_t new_val)
 Atomically fetches 32-bit value from memory and stores a new value.
static PFUNC_INLINE int8_t pfunc_fetch_and_add_8 (volatile void *location, int8_t addend)
 Atomically fetches 8-bit value from memory and adds to it.
static PFUNC_INLINE int16_t pfunc_fetch_and_add_16 (volatile void *location, int16_t addend)
 Atomically fetches 16-bit value from memory and adds to it.
static PFUNC_INLINE int32_t pfunc_fetch_and_add_32 (volatile void *location, int32_t addend)
 Atomically fetches 32-bit value from memory and adds to it.
static PFUNC_INLINE int8_t pfunc_read_with_fence_8 (volatile void *location)
 Read an 8-bit value and insert a fence after the read.
static PFUNC_INLINE int16_t pfunc_read_with_fence_16 (volatile void *location)
 Read an 16-bit value and insert a fence after the read.
static PFUNC_INLINE int32_t pfunc_read_with_fence_32 (volatile void *location)
 Read an 32-bit value and insert a fence after the read.
static PFUNC_INLINE void pfunc_write_with_fence_8 (volatile void *location, int8_t value)
 Write an 8-bit value and insert a fence before the write.
static PFUNC_INLINE void pfunc_write_with_fence_16 (volatile void *location, int16_t value)
 Write an 16-bit value and insert a fence before the write.
static PFUNC_INLINE void pfunc_write_with_fence_32 (volatile void *location, int32_t value)
 Write an 32-bit value and insert a fence before the write.

Detailed Description

Implements atomic operations on PODs.

Author:
Prabhanjan Kambadur

Define Documentation

#define PFUNC_CONST_CAST (   T,
  expr 
)    (T)(expr)
#define PFUNC_DYNAMIC_CAST (   T,
  expr 
)    (T)(expr)
#define PFUNC_REINTERPRET_CAST (   T,
  expr 
)    (T)(expr)
#define PFUNC_STATIC_CAST (   T,
  expr 
)    (T)(expr)

Function Documentation

static PFUNC_INLINE int16_t pfunc_compare_and_swap_16 ( volatile void *  dest,
int16_t  exchg,
int16_t  comprnd 
) [static]

Compare and Swap an 16-bit memory location.

Parameters:
destPointer to the memory location of the operand
exchgThe new value to which dest has to be set if successful
comprndThe value that is compared to the memory location
 if (*dest == comprnd) {
   *dest = exchg;
   return exchg;
 } else {
   return *dest;
 }  
static PFUNC_INLINE int32_t pfunc_compare_and_swap_32 ( volatile void *  dest,
int32_t  exchg,
int32_t  comprnd 
) [static]

Compare and Swap an 32-bit memory location.

Parameters:
destPointer to the memory location of the operand
exchgThe new value to which dest has to be set if successful
comprndThe value that is compared to the memory location
 if (*dest == comprnd) {
   *dest = exchg;
   return exchg;
 } else {
   return *dest;
 }  
static PFUNC_INLINE int8_t pfunc_compare_and_swap_8 ( volatile void *  dest,
int8_t  exchg,
int8_t  comprnd 
) [static]

Compare and Swap an 8-bit memory location.

Parameters:
destPointer to the memory location of the operand
exchgThe new value to which dest has to be set if successful
comprndThe value that is compared to the memory location
 if (*dest == comprnd) {
   *dest = exchg;
   return exchg;
 } else {
   return *dest;
 }  
static PFUNC_INLINE int16_t pfunc_fetch_and_add_16 ( volatile void *  location,
int16_t  addend 
) [static]

Atomically fetches 16-bit value from memory and adds to it.

Parameters:
locationPointer to memory location
addendThe increment to the memory location.
 result = *location;
 *location += addend;
 return result;
static PFUNC_INLINE int32_t pfunc_fetch_and_add_32 ( volatile void *  location,
int32_t  addend 
) [static]

Atomically fetches 32-bit value from memory and adds to it.

Parameters:
locationPointer to memory location
addendThe increment to the memory location.
 result = *location;
 *location += addend;
 return result;
static PFUNC_INLINE int8_t pfunc_fetch_and_add_8 ( volatile void *  location,
int8_t  addend 
) [static]

Atomically fetches 8-bit value from memory and adds to it.

Parameters:
locationPointer to memory location
addendThe increment to the memory location.
 result = *location;
 *location += addend;
 return result;
static PFUNC_INLINE int16_t pfunc_fetch_and_store_16 ( volatile void *  location,
int16_t  new_val 
) [static]

Atomically fetches 16-bit value from memory and stores a new value.

Parameters:
locationPointer to memory location
new_valThe new value to be atomically written in
 result = *location;
 *location = new_val;
 return result;
static PFUNC_INLINE int32_t pfunc_fetch_and_store_32 ( volatile void *  location,
int32_t  new_val 
) [static]

Atomically fetches 32-bit value from memory and stores a new value.

Parameters:
locationPointer to memory location
new_valThe new value to be atomically written in
 result = *location;
 *location = new_val;
 return result;
static PFUNC_INLINE int8_t pfunc_fetch_and_store_8 ( volatile void *  location,
int8_t  new_val 
) [static]

Atomically fetches 8-bit value from memory and stores a new value.

Parameters:
locationPointer to memory location
new_valThe new value to be atomically written in
 result = *location;
 *location = new_val;
 return result;
static PFUNC_INLINE int16_t pfunc_read_with_fence_16 ( volatile void *  location) [static]

Read an 16-bit value and insert a fence after the read.

Parameters:
locationThe memory from which to read
Returns:
Value at location
static PFUNC_INLINE int32_t pfunc_read_with_fence_32 ( volatile void *  location) [static]

Read an 32-bit value and insert a fence after the read.

Parameters:
locationThe memory from which to read
Returns:
Value at location
static PFUNC_INLINE int8_t pfunc_read_with_fence_8 ( volatile void *  location) [static]

Read an 8-bit value and insert a fence after the read.

Parameters:
locationThe memory from which to read
Returns:
Value at location
static PFUNC_INLINE void pfunc_write_with_fence_16 ( volatile void *  location,
int16_t  value 
) [static]

Write an 16-bit value and insert a fence before the write.

Parameters:
locationThe memory to write to
valueThe value to write
static PFUNC_INLINE void pfunc_write_with_fence_32 ( volatile void *  location,
int32_t  value 
) [static]

Write an 32-bit value and insert a fence before the write.

Parameters:
locationThe memory to write to
valueThe value to write
static PFUNC_INLINE void pfunc_write_with_fence_8 ( volatile void *  location,
int8_t  value 
) [static]

Write an 8-bit value and insert a fence before the write.

Parameters:
locationThe memory to write to
valueThe value to write