File: ovs-atomic-locked.h

package info (click to toggle)
openvswitch 3.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 97,848 kB
  • sloc: sh: 1,643,930; ansic: 313,386; python: 27,939; xml: 21,526; makefile: 546; javascript: 191
file content (52 lines) | stat: -rw-r--r-- 1,958 bytes parent folder | download | duplicates (2)
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
/* This header implements atomic operation locking helpers. */
#ifndef IN_OVS_ATOMIC_H
#error "This header should only be included indirectly via ovs-atomic.h."
#endif

#define OVS_ATOMIC_LOCKED_IMPL 1

void atomic_lock__(void *);
void atomic_unlock__(void *);

#define atomic_store_locked(DST, SRC)           \
    (atomic_lock__(DST),                        \
     *(DST) = (SRC),                            \
     atomic_unlock__(DST),                      \
     (void) 0)

#define atomic_read_locked(SRC, DST)            \
    (atomic_lock__(SRC),                        \
     *(DST) = *(SRC),                           \
     atomic_unlock__(SRC),                      \
     (void) 0)

/* XXX: Evaluates EXP multiple times. */
#define atomic_compare_exchange_locked(DST, EXP, SRC)   \
    (atomic_lock__(DST),                                \
     (*(DST) == *(EXP)                                  \
      ? (*(DST) = (SRC),                                \
         atomic_unlock__(DST),                          \
         true)                                          \
      : (*(EXP) = *(DST),                               \
         atomic_unlock__(DST),                          \
         false)))

#define atomic_exchange_locked(DST, SRC)     \
    ({                                       \
        atomic_lock__(DST);                  \
        typeof(*(DST)) __tmp = *(DST);       \
        *(DST) = SRC;                        \
        atomic_unlock__(DST);                \
        __tmp;                               \
    })

#define atomic_op_locked_add +=
#define atomic_op_locked_sub -=
#define atomic_op_locked_or  |=
#define atomic_op_locked_xor ^=
#define atomic_op_locked_and &=
#define atomic_op_locked(RMW, OP, OPERAND, ORIG)    \
    (atomic_lock__(RMW),                            \
     *(ORIG) = *(RMW),                              \
     *(RMW) atomic_op_locked_##OP (OPERAND),        \
     atomic_unlock__(RMW))