Line data Source code
1 : /* Any copyright is dedicated to the Public Domain.
2 : * http://creativecommons.org/publicdomain/zero/1.0/ */
3 :
4 : #ifndef ATOMIC_H_
5 : #define ATOMIC_H_
6 :
7 : #include <stdint.h>
8 :
9 : // This implements the atomic primatives without any atomicity guarantees. This
10 : // makes the totally unsafe. However we're only using the demuxer in a single
11 : // thread.
12 :
13 : namespace stagefright {
14 : static inline int32_t
15 0 : android_atomic_dec(volatile int32_t* aValue)
16 : {
17 0 : return (*aValue)--;
18 : }
19 :
20 : static inline int32_t
21 0 : android_atomic_inc(volatile int32_t* aValue)
22 : {
23 0 : return (*aValue)++;
24 : }
25 :
26 : static inline int32_t
27 0 : android_atomic_or(int32_t aModifier, volatile int32_t* aValue)
28 : {
29 0 : int32_t ret = *aValue;
30 0 : *aValue |= aModifier;
31 0 : return ret;
32 : }
33 :
34 : static inline int32_t
35 0 : android_atomic_add(int32_t aModifier, volatile int32_t* aValue)
36 : {
37 0 : int32_t ret = *aValue;
38 0 : *aValue += aModifier;
39 0 : return ret;
40 : }
41 :
42 : static inline int32_t
43 0 : android_atomic_cmpxchg(int32_t aOld, int32_t aNew, volatile int32_t* aValue)
44 : {
45 0 : if (*aValue == aOld)
46 : {
47 0 : return *aValue = aNew;
48 : }
49 0 : return aOld;
50 : }
51 : }
52 :
53 : #endif
|