summaryrefslogtreecommitdiffstats
path: root/stacks/lwip_stack/release/lwip_helper_files/lwip/arch/atomic_32.h
blob: 15a058b97b9a1e7f3338a062dcf9a3ccf5a30e72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 * atomic_32.h
 *
 */

#ifndef ATOMIC_32_H_
#define ATOMIC_32_H_

#ifdef __cplusplus
extern "C"
{
#endif

  typedef struct
  {
    volatile int counter;
  } atomic_t;

#define ATOMIC_INIT(i) {(i)}
#define atomic_read(v) (*(volatile int *)&(v)->counter)
#define atomic_set(v, i) (((v)->counter) = (i))

  static inline void atomic_add (int i, atomic_t * v)
  {
    __asm__ __volatile__ (
                           /*LOCK_PREFIX "addl %1,%0" */
                           "addl %1,%0":"+m" (v->counter):"ir" (i));
  }

  static inline void atomic_sub (int i, atomic_t * v)
  {
    __asm__ __volatile__ (
                           /*LOCK_PREFIX "subl %1,%0" */
                           "subl %1,%0":"+m" (v->counter):"ir" (i));
  }

  static __inline__ void atomic_inc (atomic_t * v)
  {
    __asm__ __volatile__ (
                           /*LOCK_PREFIX "incl %0" */
                           "incl %0":"+m" (v->counter));
  }

  static __inline__ void atomic_dec (atomic_t * v)
  {
    __asm__ __volatile__ (
                           /*LOCK_PREFIX "decl %0" */
                           "decl %0":"+m" (v->counter));
  }
#ifdef __cplusplus
}
#endif
#endif /* ATOMIC_32_H_ */