summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/stubs/include/cutils/atomic.h
blob: e225501779575436c4a321db92d760c00434f731 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

#ifndef ATOMIC_H_
#define ATOMIC_H_

#include <stdint.h>

// This implements the atomic primatives without any atomicity guarantees. This
// makes the totally unsafe. However we're only using the demuxer in a single
// thread.

namespace stagefright {
static inline int32_t
android_atomic_dec(volatile int32_t* aValue)
{
  return (*aValue)--;
}

static inline int32_t
android_atomic_inc(volatile int32_t* aValue)
{
  return (*aValue)++;
}

static inline int32_t
android_atomic_or(int32_t aModifier, volatile int32_t* aValue)
{
  int32_t ret = *aValue;
  *aValue |= aModifier;
  return ret;
}

static inline int32_t
android_atomic_add(int32_t aModifier, volatile int32_t* aValue)
{
  int32_t ret = *aValue;
  *aValue += aModifier;
  return ret;
}

static inline int32_t
android_atomic_cmpxchg(int32_t aOld, int32_t aNew, volatile int32_t* aValue)
{
  if (*aValue == aOld)
  {
    return *aValue = aNew;
  }
  return aOld;
}
}

#endif