| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2006, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: batomic.h $ |
|---|
| 11 | * $brcm_Revision: 3 $ |
|---|
| 12 | * $brcm_Date: 12/13/06 7:47p $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Atomic operations |
|---|
| 17 | * |
|---|
| 18 | * Revision History: |
|---|
| 19 | * |
|---|
| 20 | * $brcm_Log: /BSEAV/lib/bprofile/batomic.h $ |
|---|
| 21 | * |
|---|
| 22 | * 3 12/13/06 7:47p vsilyaev |
|---|
| 23 | * PR 25997: Don't instrument atomic functions |
|---|
| 24 | * |
|---|
| 25 | * 2 12/7/06 2:44p vsilyaev |
|---|
| 26 | * PR 25997: Added fixes for 3.4 GCC compiler |
|---|
| 27 | * |
|---|
| 28 | * 1 11/30/06 8:31p vsilyaev |
|---|
| 29 | * PR 25997: Automic variable |
|---|
| 30 | * |
|---|
| 31 | * |
|---|
| 32 | *******************************************************************************/ |
|---|
| 33 | #ifndef __BATOMIC_H__ |
|---|
| 34 | #define __BATOMIC_H__ |
|---|
| 35 | |
|---|
| 36 | #ifdef __cplusplus |
|---|
| 37 | extern "C" |
|---|
| 38 | { |
|---|
| 39 | #endif |
|---|
| 40 | |
|---|
| 41 | typedef struct batomic_t { |
|---|
| 42 | volatile int atomic; |
|---|
| 43 | } batomic_t; |
|---|
| 44 | |
|---|
| 45 | #define BATOMIC_INIT(v) {(v)} |
|---|
| 46 | #ifndef BSTD_INLINE |
|---|
| 47 | #define BSTD_INLINE extern inline __attribute__((always_inline)) |
|---|
| 48 | #endif |
|---|
| 49 | |
|---|
| 50 | BSTD_INLINE void __attribute__((no_instrument_function)) |
|---|
| 51 | batomic_set(batomic_t *a, int val) { |
|---|
| 52 | a->atomic = val; |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | BSTD_INLINE int __attribute__((no_instrument_function)) |
|---|
| 56 | batomic_get(const batomic_t *a) { |
|---|
| 57 | return a->atomic; |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | BSTD_INLINE int __attribute__((no_instrument_function)) |
|---|
| 61 | batomic_add_return(batomic_t *a, int val) |
|---|
| 62 | { |
|---|
| 63 | unsigned temp, result; |
|---|
| 64 | |
|---|
| 65 | __asm__ __volatile__( |
|---|
| 66 | " .set mips32 \n" |
|---|
| 67 | "1: ll %1, %2 # b_atomic_add_return\n" |
|---|
| 68 | " addu %0, %1, %3 \n" |
|---|
| 69 | " sc %0, %2 \n" |
|---|
| 70 | " beqz %0, 1b \n" |
|---|
| 71 | " addu %0, %1, %3 \n" |
|---|
| 72 | " .set mips0 \n" |
|---|
| 73 | : "=&r" (result), "=&r" (temp), "=m" (a->atomic) |
|---|
| 74 | : "Ir" (val), "m" (a->atomic) |
|---|
| 75 | : "memory"); |
|---|
| 76 | return result; |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | #ifdef __cplusplus |
|---|
| 81 | } |
|---|
| 82 | #endif |
|---|
| 83 | |
|---|
| 84 | #endif /* __BATOMIC_H__ */ |
|---|