1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/omx-plugin/include/froyo/cutils/atomic.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,79 @@ 1.4 +/* 1.5 + * Copyright (C) 2007 The Android Open Source Project 1.6 + * 1.7 + * Licensed under the Apache License, Version 2.0 (the "License"); 1.8 + * you may not use this file except in compliance with the License. 1.9 + * You may obtain a copy of the License at 1.10 + * 1.11 + * http://www.apache.org/licenses/LICENSE-2.0 1.12 + * 1.13 + * Unless required by applicable law or agreed to in writing, software 1.14 + * distributed under the License is distributed on an "AS IS" BASIS, 1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.16 + * See the License for the specific language governing permissions and 1.17 + * limitations under the License. 1.18 + */ 1.19 + 1.20 +#ifndef ANDROID_CUTILS_ATOMIC_H 1.21 +#define ANDROID_CUTILS_ATOMIC_H 1.22 + 1.23 +#include <stdint.h> 1.24 +#include <sys/types.h> 1.25 + 1.26 +#ifdef __cplusplus 1.27 +extern "C" { 1.28 +#endif 1.29 + 1.30 +/* 1.31 + * NOTE: memory shared between threads is synchronized by all atomic operations 1.32 + * below, this means that no explicit memory barrier is required: all reads or 1.33 + * writes issued before android_atomic_* operations are guaranteed to complete 1.34 + * before the atomic operation takes place. 1.35 + */ 1.36 + 1.37 +void android_atomic_write(int32_t value, volatile int32_t* addr); 1.38 + 1.39 +/* 1.40 + * all these atomic operations return the previous value 1.41 + */ 1.42 + 1.43 + 1.44 +int32_t android_atomic_inc(volatile int32_t* addr); 1.45 +int32_t android_atomic_dec(volatile int32_t* addr); 1.46 + 1.47 +int32_t android_atomic_add(int32_t value, volatile int32_t* addr); 1.48 +int32_t android_atomic_and(int32_t value, volatile int32_t* addr); 1.49 +int32_t android_atomic_or(int32_t value, volatile int32_t* addr); 1.50 + 1.51 +int32_t android_atomic_swap(int32_t value, volatile int32_t* addr); 1.52 + 1.53 +/* 1.54 + * NOTE: Two "quasiatomic" operations on the exact same memory address 1.55 + * are guaranteed to operate atomically with respect to each other, 1.56 + * but no guarantees are made about quasiatomic operations mixed with 1.57 + * non-quasiatomic operations on the same address, nor about 1.58 + * quasiatomic operations that are performed on partially-overlapping 1.59 + * memory. 1.60 + */ 1.61 + 1.62 +int64_t android_quasiatomic_swap_64(int64_t value, volatile int64_t* addr); 1.63 +int64_t android_quasiatomic_read_64(volatile int64_t* addr); 1.64 + 1.65 +/* 1.66 + * cmpxchg return a non zero value if the exchange was NOT performed, 1.67 + * in other words if oldvalue != *addr 1.68 + */ 1.69 + 1.70 +int android_atomic_cmpxchg(int32_t oldvalue, int32_t newvalue, 1.71 + volatile int32_t* addr); 1.72 + 1.73 +int android_quasiatomic_cmpxchg_64(int64_t oldvalue, int64_t newvalue, 1.74 + volatile int64_t* addr); 1.75 + 1.76 + 1.77 + 1.78 +#ifdef __cplusplus 1.79 +} // extern "C" 1.80 +#endif 1.81 + 1.82 +#endif // ANDROID_CUTILS_ATOMIC_H