1,5 → 1,5 |
/* |
* Copyright (c) 2005 Jakub Jermar |
* Copyright (c) 2007 Michal Kebrt |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
38,14 → 38,30 |
/** Atomic addition. |
* |
* @param val Atomic value. |
* @param imm Value to add. |
* @param i Value to add. |
* |
* @return Value after addition. |
*/ |
static inline long atomic_add(atomic_t *val, int imm) |
static inline long atomic_add(atomic_t *val, int i) |
{ |
/* TODO */ |
return (val->count += imm); |
int ret; |
volatile long * mem = &(val->count); |
|
asm volatile ( |
"1: \n" |
"ldr r2, [%1] \n" |
"add r3, r2, %2 \n" |
"str r3, %0 \n" |
"swp r3, r3, [%1] \n" |
"cmp r3, r2 \n" |
"bne 1b \n" |
|
: "=m" (ret) |
: "r" (mem), "r" (i) |
: "r3", "r2" |
); |
|
return ret; |
} |
|
static inline void atomic_inc(atomic_t *val) { atomic_add(val, 1); } |