Loading...
Searching...
No Matches
sasatom.h File Reference

Type and functions for SAS atomic operations. More...

`#include <sched.h>`
`#include "sasatom_generic.h"`

Go to the source code of this file.

## Macros

#define | sas_write_barrier()
#define | sas_read_barrier()
#define | sas_full_barrier()
#define | sas_code_barrier()

## Typedefs

typedef unsigned int | sas_spin_lock_t
typedef void * | sas_lock_ptr_t

## Functions

static void * | sas_fetch_and_add_ptr (void **pointer, long int delta)
static long int | sas_fetch_and_add (long *pointer, long int delta)
static long int | sas_fetch_and_and (unsigned int *pointer, int delta)
static long int | sas_fetch_and_and_long (unsigned long *pointer, long int delta)
static long int | sas_fetch_and_or (unsigned int *pointer, int delta)
static long int | sas_fetch_and_or_long (unsigned long *pointer, long int delta)
static int | sas_compare_and_swap (volatile long int *p, long int oldval, long int newval)
static long int | sas_atomic_swap (long int *p, long int replace)
static void | sas_atomic_inc (long int *p)
static void | sas_atomic_dec (long int *p)
static void | sas_spin_lock_init (volatile sas_spin_lock_t *lock)
static void | sas_spin_lock (volatile sas_spin_lock_t *lock)
static int | sas_spin_trylock (volatile sas_spin_lock_t *lock)
static void | sas_spin_unlock (volatile sas_spin_lock_t *lock)
static void | sas_lock_ptr_init (volatile sas_lock_ptr_t *lock)
static void * | sas_lock_ptr (volatile sas_lock_ptr_t *lock)
static void | sas_set_unlocked_ptr (volatile sas_lock_ptr_t *lock, sas_lock_ptr_t newptr)
static void | sas_set_locked_ptr (volatile sas_lock_ptr_t *lock, sas_lock_ptr_t newptr)
static int | sas_trylock_ptr (volatile sas_lock_ptr_t *lock)
static void | sas_unlock_ptr (volatile sas_lock_ptr_t *lock)
static void | sas_spin_lock_with_yield (volatile sas_spin_lock_t *lock)
static void | sas_lock_ptr_with_yield (volatile sas_lock_ptr_t *lock)
static long | sas_atomic_inc_long (volatile long *value)
static long | sas_atomic_dec_long (volatile long *value)

## Detailed Description

Type and functions for SAS atomic operations.

This file contains generic SAS atomic functions. Architecture specific code is in its correpondent header ('sasatom_ppc.h' for PowerPC32 and PowerPC64, 'sasatom_i386.h' for i386, and 'sasatom_x86_64.h' for X86_64). The 'sasatom_generic.h' header is provided as reference implementation and it is not garanted to work correctly.

## Macro Definition Documentation

## sas_code_barrier

#define sas_code_barrier | ( |  | ) |

Value:
__asm ("" ::: "memory")

Memory barrier for compiler code motion.

## sas_full_barrier

#define sas_full_barrier | ( |  | ) |

Value:
__arch_sas_full_barrier()

Memory barrier for both load/store operations.

## sas_read_barrier

#define sas_read_barrier | ( |  | ) |

Value:
__arch_sas_read_barrier()

Memory barrier for load operations.

## sas_write_barrier

#define sas_write_barrier | ( |  | ) |

Value:
__arch_sas_write_barrier()

Memory barrier for store operations.

## Typedef Documentation

## sas_lock_ptr_t

typedef void* sas_lock_ptr_t

Pointer to sas_spin_lock_t type

## sas_spin_lock_t

typedef unsigned int sas_spin_lock_t

Spinlock type used on sas_spin_xxx functions

## Function Documentation

## sas_atomic_dec()

void sas_atomic_dec | ( | long int * | p | ) |

inline static

Atomic decrement, performing { (*p)– }

## sas_atomic_dec_long()

long sas_atomic_dec_long | ( | volatile long * | value | ) |

inline static

Atomically decrements value by 1.

## sas_atomic_inc()

void sas_atomic_inc | ( | long int * | p | ) |

inline static

Atomic increment, performing { (*p)++ }

## sas_atomic_inc_long()

long sas_atomic_inc_long | ( | volatile long * | value | ) |

inline static

Atomically increments value by 1.

## sas_atomic_swap()

long int sas_atomic_swap | ( | long int * | p,
|  | long int | replace )

inline static

Atomic swap operation.

Performs the atomic operation: { tmp = *p; *p = tmp; return tmp }

## sas_compare_and_swap()

int sas_compare_and_swap | ( | volatile long int * | p,
|  | long int | oldval,
|  | long int | newval )

inline static

Atomic compare and swap operation.

Performs the atomic operation: { *p == oldval ? *p = newval : *p; return *p }

Returns oldval.

## sas_fetch_and_add()

long int sas_fetch_and_add | ( | long * | pointer,
|  | long int | delta )

inline static

Atomic fetch and add operation on memory pointer.

Performs the atomic operation: { tmp = *pointer; *pointer = tmp + delta; return *pointer }

Returns *pointer before update.

## sas_fetch_and_add_ptr()

void * sas_fetch_and_add_ptr | ( | void ** | pointer,
|  | long int | delta )

inline static

Atomic fetch and add operation on memory referenced by pointer.

Performs the atomic operation: { tmp = **pointer; **pointer = tmp + delta; return *pointer }

Returns *pointer before update.

## sas_fetch_and_and()

long int sas_fetch_and_and | ( | unsigned int * | pointer,
|  | int | delta )

inline static

Atomic fetch and and operation on memory pointer of int type.

Performs the atomic operation: { tmp = *pointer; *pointer = tmp & delta; return *pointer }

Returns *pointer before update.

## sas_fetch_and_and_long()

long int sas_fetch_and_and_long | ( | unsigned long * | pointer,
|  | long int | delta )

inline static

Atomic fetch and and operation on memory pointer of long type.

Performs the atomic operation: { tmp = *pointer; *pointer = tmp & delta; return *pointer }

Returns *pointer before update.

## sas_fetch_and_or()

long int sas_fetch_and_or | ( | unsigned int * | pointer,
|  | int | delta )

inline static

Atomic fetch and or operation on memory pointer of int type.

Performs the atomic operation: { tmp = *pointer; *pointer = tmp | delta; return *pointer }

Returns *pointer before update.

## sas_fetch_and_or_long()

long int sas_fetch_and_or_long | ( | unsigned long * | pointer,
|  | long int | delta )

inline static

Atomic fetch and or operation on memory pointer of long type.

Performs the atomic operation: { tmp = *pointer; *pointer = tmp | delta; return *pointer }

Returns *pointer before update.

## sas_lock_ptr()

void * sas_lock_ptr | ( | volatile sas_lock_ptr_t * | lock | ) |

inline static

Locks the spinlock pointer lock and returns its unlocked value.

## sas_lock_ptr_init()

void sas_lock_ptr_init | ( | volatile sas_lock_ptr_t * | lock | ) |

inline static

Initializes the spinlock pointer lock so it can be used with lock and unlock functions.

## sas_lock_ptr_with_yield()

void sas_lock_ptr_with_yield | ( | volatile sas_lock_ptr_t * | lock | ) |

inline static

The function tried 4 times to lock lock pointer and if it fails it calls 'sched_yield' returning with another lock try.

## sas_set_locked_ptr()

void sas_set_locked_ptr | ( | volatile sas_lock_ptr_t * | lock,
|  | sas_lock_ptr_t | newptr )

inline static

Spins over lock lock until it is locked then swap its value with newptr locked value.

## sas_set_unlocked_ptr()

void sas_set_unlocked_ptr | ( | volatile sas_lock_ptr_t * | lock,
|  | sas_lock_ptr_t | newptr )

inline static

Spins over spinlock pointer lock until it is unlocked then swap its value with newptr locked value.

## sas_spin_lock()

void sas_spin_lock | ( | volatile sas_spin_lock_t * | lock | ) |

inline static

Locks the spinlock lock.

The function uses a busylock algorithm in the form: while ({tmp = *lock; *lock = 1; });

## sas_spin_lock_init()

void sas_spin_lock_init | ( | volatile sas_spin_lock_t * | lock | ) |

inline static

Initializes the spinlock lock so it can be used with lock and unlock functions.

## sas_spin_lock_with_yield()

void sas_spin_lock_with_yield | ( | volatile sas_spin_lock_t * | lock | ) |

inline static

The function tries 4 times to lock lock and if it fails it calls 'sched_yield' returning with another lock try.

## sas_spin_trylock()

int sas_spin_trylock | ( | volatile sas_spin_lock_t * | lock | ) |

inline static

Try to lock the spinlock lock.

It returns if the lock lock can not be locked.

Returns 1 if the spinlock was locked, 0 otherwise.

## sas_spin_unlock()

void sas_spin_unlock | ( | volatile sas_spin_lock_t * | lock | ) |

inline static

Unlocks the spinlock lock reseting it to initial value.

## sas_trylock_ptr()

int sas_trylock_ptr | ( | volatile sas_lock_ptr_t * | lock | ) |

inline static

The function tried to lock lock. If the operation is successful the function return 0 or 1 otherwise.

## sas_unlock_ptr()

void sas_unlock_ptr | ( | volatile sas_lock_ptr_t * | lock | ) |

inline static

Unlocks the spinlock lock.