Subversion Repositories HelenOS

Rev

Rev 2927 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2927 Rev 4345
Line 24... Line 24...
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
/** @addtogroup arm32  
29
/** @addtogroup arm32
30
 * @{
30
 * @{
31
 */
31
 */
32
/** @file
32
/** @file
33
 *  @brief Atomic operations.
33
 *  @brief Atomic operations.
34
 */
34
 */
35
 
35
 
36
#ifndef KERN_arm32_ATOMIC_H_
36
#ifndef KERN_arm32_ATOMIC_H_
37
#define KERN_arm32_ATOMIC_H_
37
#define KERN_arm32_ATOMIC_H_
Line 40... Line 40...
40
 *
40
 *
41
 * @param val Where to add.
41
 * @param val Where to add.
42
 * @param i   Value to be added.
42
 * @param i   Value to be added.
43
 *
43
 *
44
 * @return Value after addition.
44
 * @return Value after addition.
-
 
45
 *
45
 */
46
 */
46
static inline long atomic_add(atomic_t *val, int i)
47
static inline long atomic_add(atomic_t *val, int i)
47
{
48
{
48
    int ret;
49
    int ret;
49
    volatile long *mem = &(val->count);
50
    volatile long *mem = &(val->count);
50
 
51
   
51
    asm volatile (
52
    asm volatile (
52
    "1:\n"
53
        "1:\n"
53
        "ldr r2, [%1]       \n"
54
            "ldr r2, [%[mem]]\n"
54
        "add r3, r2, %2     \n"
55
            "add r3, r2, %[i]\n"
55
        "str r3, %0         \n"
56
            "str r3, %[ret]\n"
56
        "swp r3, r3, [%1]   \n"
57
            "swp r3, r3, [%[mem]]\n"
57
        "cmp r3, r2         \n"
58
            "cmp r3, r2\n"
58
        "bne 1b             \n"
59
            "bne 1b\n"
59
 
-
 
60
        : "=m" (ret)
60
        : [ret] "=m" (ret)
61
        : "r" (mem), "r" (i)
61
        : [mem] "r" (mem), [i] "r" (i)
62
        : "r3", "r2"
62
        : "r3", "r2"
63
    );
63
    );
64
 
64
   
65
    return ret;
65
    return ret;
66
}
66
}
67
 
67
 
68
/** Atomic increment.
68
/** Atomic increment.
69
 *
69
 *