Subversion Repositories HelenOS

Rev

Rev 2131 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2131 Rev 2287
Line 1... Line 1...
1
/*
1
/*
2
 * Copyright (c) 2005 Jakub Jermar
2
 * Copyright (c) 2007 Michal Kebrt
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
Line 36... Line 36...
36
#define LIBC_arm32_ATOMIC_H_
36
#define LIBC_arm32_ATOMIC_H_
37
 
37
 
38
/** Atomic addition.
38
/** Atomic addition.
39
 *
39
 *
40
 * @param val Atomic value.
40
 * @param val Atomic value.
41
 * @param imm Value to add.
41
 * @param i Value to add.
42
 *
42
 *
43
 * @return Value after addition.
43
 * @return Value after addition.
44
 */
44
 */
45
static inline long atomic_add(atomic_t *val, int imm)
45
static inline long atomic_add(atomic_t *val, int i)
46
{
46
{
-
 
47
    int ret;
-
 
48
    volatile long * mem = &(val->count);
-
 
49
 
-
 
50
    asm volatile (
-
 
51
        "1:                 \n"
-
 
52
        "ldr r2, [%1]       \n"
-
 
53
        "add r3, r2, %2     \n"
-
 
54
        "str r3, %0         \n"
-
 
55
        "swp r3, r3, [%1]   \n"
-
 
56
        "cmp r3, r2         \n"
-
 
57
        "bne 1b             \n"
-
 
58
 
47
    /* TODO */
59
        : "=m" (ret)
48
    return (val->count += imm);
60
        : "r" (mem), "r" (i)
-
 
61
        : "r3", "r2"
-
 
62
    );
-
 
63
 
-
 
64
    return ret;
49
}
65
}
50
 
66
 
51
static inline void atomic_inc(atomic_t *val) { atomic_add(val, 1); }
67
static inline void atomic_inc(atomic_t *val) { atomic_add(val, 1); }
52
static inline void atomic_dec(atomic_t *val) { atomic_add(val, -1); }
68
static inline void atomic_dec(atomic_t *val) { atomic_add(val, -1); }
53
 
69