Changeset cfa70add in mainline for uspace/libc/arch/sparc64/include/atomic.h
- Timestamp:
- 2006-09-03T23:37:14Z (18 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- fd85ae5
- Parents:
- 002e613
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/libc/arch/sparc64/include/atomic.h
r002e613 rcfa70add 1 1 /* 2 * Copyright (C) 2005 Martin Decky2 * Copyright (C) 2005 Jakub Jermar 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup libcsparc64 29 /** @addtogroup libcsparc64 30 30 * @{ 31 31 */ … … 33 33 */ 34 34 35 #ifndef __sparc64_ATOMIC_H__ 36 #define __sparc64_ATOMIC_H__ 35 #ifndef LIBC_sparc64_ATOMIC_H_ 36 #define LIBC_sparc64_ATOMIC_H_ 37 38 #include <types.h> 39 40 /** Atomic add operation. 41 * 42 * Use atomic compare and swap operation to atomically add signed value. 43 * 44 * @param val Atomic variable. 45 * @param i Signed value to be added. 46 * 47 * @return Value of the atomic variable as it existed before addition. 48 */ 49 static inline long atomic_add(atomic_t *val, int i) 50 { 51 uint64_t a, b; 52 volatile uint64_t x = (uint64_t) &val->count; 53 54 __asm__ volatile ( 55 "0:\n" 56 "ldx %0, %1\n" 57 "add %1, %3, %2\n" 58 "casx %0, %1, %2\n" 59 "cmp %1, %2\n" 60 "bne 0b\n" /* The operation failed and must be attempted again if a != b. */ 61 "nop\n" 62 : "=m" (*((uint64_t *)x)), "=r" (a), "=r" (b) 63 : "r" (i) 64 ); 65 66 return a; 67 } 68 69 static inline long atomic_preinc(atomic_t *val) 70 { 71 return atomic_add(val, 1) + 1; 72 } 73 74 static inline long atomic_postinc(atomic_t *val) 75 { 76 return atomic_add(val, 1); 77 } 78 79 static inline long atomic_predec(atomic_t *val) 80 { 81 return atomic_add(val, -1) - 1; 82 } 83 84 static inline long atomic_postdec(atomic_t *val) 85 { 86 return atomic_add(val, -1); 87 } 37 88 38 89 static inline void atomic_inc(atomic_t *val) 39 90 { 91 (void) atomic_add(val, 1); 40 92 } 41 93 42 94 static inline void atomic_dec(atomic_t *val) 43 95 { 44 } 45 46 static inline long atomic_postinc(atomic_t *val) 47 { 48 atomic_inc(val); 49 return val->count - 1; 50 } 51 52 static inline long atomic_postdec(atomic_t *val) 53 { 54 atomic_dec(val); 55 return val->count + 1; 56 } 57 58 static inline long atomic_preinc(atomic_t *val) 59 { 60 atomic_inc(val); 61 return val->count; 62 } 63 64 static inline long atomic_predec(atomic_t *val) 65 { 66 atomic_dec(val); 67 return val->count; 96 (void) atomic_add(val, -1); 68 97 } 69 98
Note:
See TracChangeset
for help on using the changeset viewer.