atomic.h File Reference

Defines atomic types used in the MultiServices PIC SDK. More...


Defines

#define __ATOMIC32_ADD_OP(func, atomic_type, type, operation)
#define __ATOMIC_SWAP_OP(func, atomic_type, type, operation)
#define __ATOMIC32__OP(func, atomic_type, type, operation)
#define __ATOMIC64_ADD_OP(func, atomic_type, type, operation)
#define __ATOMIC64__OP(func, atomic_type, type, operation)
#define WRITE_MEMORY_BARRIER   __asm__ __volatile__("sync")
 Set a Write memory barrier, to commit all pending store cache lines in to main memory on the current CPU context.
#define READ_MEMORY_BARRIER   __asm__ __volatile__("" : : : "memory")
 Set a Read memory barrier, to get all pending load cache lines synced with main memory on the current CPU context.

Typedefs

typedef volatile int atomic_int_t
typedef volatile unsigned int atomic_uint_t
typedef volatile __int64_t atomic_int64_t
typedef volatile __uint64_t atomic_uint64_t

Functions

static int atomic_add_int (int val, atomic_int_t *ptr)
 int atomic_add_int(int val, atomic_int_t *ptr)
static unsigned int atomic_add_uint (unsigned int val, atomic_uint_t *ptr)
 unsigned int atomic_add_uint(uint val, atomic_uint_t *ptr)
static __int64_t atomic_add_int64 (__int64_t val, atomic_int64_t *ptr)
 __int64_t atomic_add_int64(__int64_t val, atomic_int64_t *ptr)
static __uint64_t atomic_add_uint64 (__uint64_t val, atomic_uint64_t *ptr)
 __uint64_t atomic_add_uint64(__uint64_t val, atomic_uint64_t *ptr)
static int atomic_sub_int (int val, atomic_int_t *ptr)
 int atomic_sub_int(int val, atomic_int_t *ptr)
static unsigned int atomic_sub_uint (unsigned int val, atomic_uint_t *ptr)
 unsigned int atomic_sub_uint(unsigned int, atomic_uint_t *ptr)
static __int64_t atomic_sub_int64 (__int64_t val, atomic_int64_t *ptr)
 __int64_t atomic_sub_int(__int64_t val, atomic_int64_t *ptr)
static __uint64_t atomic_sub_uint64 (__uint64_t val, atomic_uint64_t *ptr)
 __uint64_t atomic_sub_uint64(__uint64_t, atomic_uint64_t *ptr)
static int atomic_and_int (int val, atomic_int_t *ptr)
 int atomic_and_int(int val, atomic_int_t *ptr)
static unsigned int atomic_and_uint (unsigned int val, atomic_uint_t *ptr)
 unsigned int atomic_and_uint(unsigned int val, atomic_uint_t *ptr)
static __int64_t atomic_and_int64 (__int64_t val, atomic_int64_t *ptr)
 __int64_t atomic_and_int64(__int64_t val, atomic_int64_t *ptr)
static __uint64_t atomic_and_uint64 (__uint64_t val, atomic_uint64_t *ptr)
 __uint64_t atomic_and_uint64(__uint64_t val, atomic_uint64_t *ptr)
static int atomic_or_int (int val, atomic_int_t *ptr)
 int atomic_or_int(int val, atomic_int_t *ptr)
static unsigned int atomic_or_uint (unsigned int val, atomic_uint_t *ptr)
 int atomic_or_uint(unsigned int val, atomic_uint_t *ptr)
static __int64_t atomic_or_int64 (__int64_t val, atomic_int64_t *ptr)
 __int64_t atomic_or_int64(__int64_t val, atomic_int64_t *ptr)
static __uint64_t atomic_or_uint64 (__uint64_t val, atomic_uint64_t *ptr)
 __uint64_t atomic_or_uint64(unsigned int val, atomic_uint64_t *ptr)
static int test_and_set_int (atomic_int_t *ptr)
 int test_and_set_int(atomic_int_t *ptr)
static int test_and_set_uint (atomic_uint_t *ptr)
 int test_and_set_uint(atomic_uint_t *ptr)
static int test_and_set_int64 (atomic_int64_t *ptr)
 int test_and_set_int(atomic_int64_t *ptr)


Detailed Description

Defines atomic types used in the MultiServices PIC SDK.

Atomic types guarantee that manipulation of this data type occurs in a single instruction, ensuring that an operation gets executed to completion without interruption.


Define Documentation

#define __ATOMIC32__OP func,
atomic_type,
type,
operation   ) 
 

Value:

static inline type                                                      \
func (type val, atomic_type* ptr)                                       \
{                                                                       \
    unsigned long temp, oldval;                                         \
                                                                        \
    asm volatile(                                                       \
                 ".set push\n"                                          \
                 ".set noreorder\n"                                     \
                 "1:   ll      %1, %2\n"                                \
                 "     "operation" \n"                                  \
                 "     sc      %0, %2\n"                                \
                 "     beqz    %0, 1b\n"                                \
                 "     nop           \n"                                \
                 ".set pop\n"                                           \
                 : "=&r" (temp), "=&r" (oldval), "=m" (*ptr)            \
                 : "r" (val), "m" (*ptr)                                \
                 : "memory");                                           \
                                                                        \
    return oldval;                                                      \
}

#define __ATOMIC32_ADD_OP func,
atomic_type,
type,
operation   ) 
 

Value:

static inline type                                                      \
func (type val, atomic_type* ptr)                                       \
{                                                                       \
    asm volatile(                                                       \
                 ".set push\n"                                          \
                 ".set noreorder\n"                                     \
                 "move $8, %2\n"                                        \
                 "move $9, %3\n"                                        \
                 " "operation" \n"                                      \
                 "move %0, $8\n"                                        \
                 ".set pop\n"                                           \
                 : "=&r"(val), "+m"(*ptr)                               \
                 : "0"(val), "r"(ptr)                                   \
                 : "$8", "$9");                                         \
                                                                        \
    return val;                                                         \
}

#define __ATOMIC64__OP func,
atomic_type,
type,
operation   ) 
 

Value:

static inline type                                                      \
func (type val, atomic_type* ptr)                                       \
{                                                                       \
    type    temp, oldval, oldval_mem;                                   \
    type    val_reg;                                                    \
                                                                        \
    asm volatile(                                                       \
                 ".set push\n"                                          \
                 ".set noreorder\n"                                     \
                 "     ld      %3, %6\n"                                \
                 "1:   lld     %1, %2\n"                                \
                 "     "operation" \n"                                  \
                 "     scd     %0, %2\n"                                \
                 "     beqz    %0, 1b\n"                                \
                 "     nop           \n"                                \
                 "     sd      %1, %4\n"                                \
                 ".set pop\n"                                           \
                 : "=&r" (temp), "=&r" (oldval), "+m" (*ptr),           \
                    "=&r"(val_reg), "=m" (oldval_mem)                   \
                 : "m" (*ptr), "m" (val)                                \
                 : "memory");                                           \
                                                                        \
    return oldval_mem;                                                  \
}

#define __ATOMIC64_ADD_OP func,
atomic_type,
type,
operation   ) 
 

Value:

static inline type                                                      \
func (type val, atomic_type* ptr)                                       \
{                                                                       \
    type oldval;                                                        \
    asm volatile(                                                       \
                 ".set push\n"                                          \
                 ".set noreorder\n"                                     \
                 "ld $8, %2\n"                                          \
                 "move $9, %3\n"                                        \
                 " "operation" \n"                                      \
                 "sd $8, %0\n"                                          \
                 ".set pop\n"                                           \
                 : "=m"(oldval), "+m"(*ptr)                             \
                 : "m"(val), "r"(ptr)                                   \
                 : "$8", "$9", "memory");                               \
                                                                        \
    return oldval;                                                      \
}

#define __ATOMIC_SWAP_OP func,
atomic_type,
type,
operation   ) 
 

Value:

static inline int                                                       \
func (atomic_type* ptr)                                                 \
{                                                                       \
    int val = 1;                                                        \
    asm volatile(                                                       \
                 ".set push\n"                                          \
                 ".set noreorder\n"                                     \
                 "move $8, %2\n"                                        \
                 "move $9, %3\n"                                        \
                 ""operation" \n"                                       \
                 "move %0, $8\n"                                        \
                 ".set pop\n"                                           \
                 : "=&r"(val), "+m"(*ptr)                               \
                 : "0"(val), "r"(ptr)                                   \
                 : "$8", "$9");                                         \
                                                                        \
    return (val == 0)? 1: 0;                                            \
}


Function Documentation

static int atomic_add_int int  val,
atomic_int_t *  ptr
[inline, static]
 

int atomic_add_int(int val, atomic_int_t *ptr)

Atomically adds an integer to an atomic integer variable.

Parameters:
val The integer value to add.
[out] ptr A pointer of type atomic_int_t.
Returns:
Old value in ptr.

static __int64_t atomic_add_int64 __int64_t  val,
atomic_int64_t *  ptr
[inline, static]
 

__int64_t atomic_add_int64(__int64_t val, atomic_int64_t *ptr)

Atomically adds a 64-bit integer to an atomic 64-bit integer variable

Parameters:
val The 64-bit integer value to add.
[out] ptr A pointer of type atomic_int64_t.
Returns:
Old value in ptr.

static unsigned int atomic_add_uint unsigned int  val,
atomic_uint_t *  ptr
[inline, static]
 

unsigned int atomic_add_uint(uint val, atomic_uint_t *ptr)

Atomically adds an unsigned integer to an atomic unsigned integer variable.

Parameters:
val The unsigned integer value to add.
[out] ptr A pointer of type atomic_uint_t.
Returns:
Old value in ptr.

static __uint64_t atomic_add_uint64 __uint64_t  val,
atomic_uint64_t *  ptr
[inline, static]
 

__uint64_t atomic_add_uint64(__uint64_t val, atomic_uint64_t *ptr)

Atomically adds a 64-bit unsigned integer to an atomic 64-bit unsigned integer variable.

Parameters:
val A 64-bit unsigned integer value to add.
[out] ptr A pointer of type atomic_uint64_t.
Returns:
Old value in ptr.

static int atomic_and_int int  val,
atomic_int_t *  ptr
[inline, static]
 

int atomic_and_int(int val, atomic_int_t *ptr)

Atomically adds a logical AND operation of an integer bitmask with an integer variable.

Parameters:
val The integer value, with bitmask.
[out] ptr A pointer of type atomic_int_t.
Returns:
Old value in ptr.

static __int64_t atomic_and_int64 __int64_t  val,
atomic_int64_t *  ptr
[inline, static]
 

__int64_t atomic_and_int64(__int64_t val, atomic_int64_t *ptr)

Performs an atomic logical AND operation of a 64-bit integer bitmask with a 64-bit integer variable.

Parameters:
val A 64-bit integer value with bitmask.
[out] ptr A pointer of type atomic_int64_t.
Returns:
Old value in ptr.

static unsigned int atomic_and_uint unsigned int  val,
atomic_uint_t *  ptr
[inline, static]
 

unsigned int atomic_and_uint(unsigned int val, atomic_uint_t *ptr)

Performs an atomic logical AND operation on an unsigned integer bitmask with an unsigned integer variable.

Parameters:
val An unsigned integer value, with bitmask.
[out] ptr A pointer of type atomic_uint_t.
Returns:
Old value in ptr.

static __uint64_t atomic_and_uint64 __uint64_t  val,
atomic_uint64_t *  ptr
[inline, static]
 

__uint64_t atomic_and_uint64(__uint64_t val, atomic_uint64_t *ptr)

Performs an atomic logical AND operation between a 64-bit unsigned integer bitmask with a 64-bit unsigned integer variable.

Parameters:
val A 64-bit unsigned integer value with bitmask.
[out] ptr A pointer of type atomic_uint64_t.
Returns:
Old value in ptr.

static int atomic_or_int int  val,
atomic_int_t *  ptr
[inline, static]
 

int atomic_or_int(int val, atomic_int_t *ptr)

Performs an atomic logical OR operation between an integer and an integer variable.

Parameters:
val The integer value with bits to be set.
[out] ptr A pointer of type atomic_int_t.
Returns:
Old value in ptr.

static __int64_t atomic_or_int64 __int64_t  val,
atomic_int64_t *  ptr
[inline, static]
 

__int64_t atomic_or_int64(__int64_t val, atomic_int64_t *ptr)

Performs an atomic logical OR operation between a 64-bit integer and a 64-bit integer variable.

Parameters:
val A 64-bit integer value with bits to set.
[out] ptr A pointer of type atomic_int64_t.
Returns:
Old value in ptr.

static unsigned int atomic_or_uint unsigned int  val,
atomic_uint_t *  ptr
[inline, static]
 

int atomic_or_uint(unsigned int val, atomic_uint_t *ptr)

Performs an atomic logical OR operation between an unsigned integer and an unsigned integer variable.

Parameters:
val An unsigned integer value with bits to be set.
[out] ptr A pointer of type atomic_uint_t.
Returns:
Old value in ptr.

static __uint64_t atomic_or_uint64 __uint64_t  val,
atomic_uint64_t *  ptr
[inline, static]
 

__uint64_t atomic_or_uint64(unsigned int val, atomic_uint64_t *ptr)

Performs an atomic logical OR operation between a 64-bit unsigned integer and a 64-bit unsigned integer variable.

Parameters:
val The 64-bit unsigned integer value with bits to set.
[out] ptr A pointer of type atomic_uint64_t.
Returns:
Old value in ptr.

static int atomic_sub_int int  val,
atomic_int_t *  ptr
[inline, static]
 

int atomic_sub_int(int val, atomic_int_t *ptr)

Atomically subtracts the specified integer from an integer variable.

Parameters:
val The integer value to subtract.
[out] ptr A pointer of type atomic_int_t.
Returns:
Old value in ptr.

static __int64_t atomic_sub_int64 __int64_t  val,
atomic_int64_t *  ptr
[inline, static]
 

__int64_t atomic_sub_int(__int64_t val, atomic_int64_t *ptr)

Atomically subtracts a specified 64-bit integer from a 64-bit integer variable.

Parameters:
val The 64-bit integer value to subtract.
[out] ptr A pointer of type atomic_int64_t.
Returns:
Old value in ptr.

static unsigned int atomic_sub_uint unsigned int  val,
atomic_uint_t *  ptr
[inline, static]
 

unsigned int atomic_sub_uint(unsigned int, atomic_uint_t *ptr)

Atomically subtracts a specified unsigned integer from an unsigned integer variable.

Parameters:
val The unsigned integer value to be subtracted.
[out] ptr A pointer of type atomic_uint_t.
Returns:
Old value in ptr.

static __uint64_t atomic_sub_uint64 __uint64_t  val,
atomic_uint64_t *  ptr
[inline, static]
 

__uint64_t atomic_sub_uint64(__uint64_t, atomic_uint64_t *ptr)

Atomically subtracts a specified 64-bit unsigned integer from a 64-bit unsigned integer variable.

Parameters:
val The 64-bit unsigned integer value to subtract.
[out] ptr A pointer of type atomic_uint64_t.
Returns:
Old value in ptr.

static int test_and_set_int atomic_int_t *  ptr  )  [inline, static]
 

int test_and_set_int(atomic_int_t *ptr)

Atomically reads and sets the integer variable argument to 1 if its value is 0.

Parameters:
[out] ptr A pointer of type atomic_int_t.
Returns:
1 if ptr was not set, 0 if ptr was already set.

static int test_and_set_int64 atomic_int64_t *  ptr  )  [inline, static]
 

int test_and_set_int(atomic_int64_t *ptr)

Atomically reads and sets the 64-bit integer variable argument to 1 if its value is 0.

Parameters:
[out] ptr A pointer of type atomic_int64_t.
Returns:
1 if ptr was not set, 0 if ptr was already set.

static int test_and_set_uint atomic_uint_t *  ptr  )  [inline, static]
 

int test_and_set_uint(atomic_uint_t *ptr)

Atomically reads and sets the unsigned integer variable argument to 1 if its value is 0.

Parameters:
[out] ptr A pointer of type atomic_uint_t.
Returns:
1 if ptr was not set, 0 if ptr was already set.


2007-2009 Juniper Networks, Inc. All rights reserved. The information contained herein is confidential information of Juniper Networks, Inc., and may not be used, disclosed, distributed, modified, or copied without the prior written consent of Juniper Networks, Inc. in an express license. This information is subject to change by Juniper Networks, Inc. Juniper Networks, the Juniper Networks logo, and JUNOS are registered trademarks of Juniper Networks, Inc. in the United States and other countries. All other trademarks, service marks, registered trademarks, or registered service marks are the property of their respective owners.
Generated on Sun May 30 20:24:47 2010 for libmp-sdk by Doxygen 1.4.5