atomic-inline.h revision b60d9ce1fcedf264f7cd7eb9fb8895b118f72ac3
1e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy/* 2e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * Copyright (C) 2010 The Android Open Source Project 3e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * 4e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * Licensed under the Apache License, Version 2.0 (the "License"); 5e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * you may not use this file except in compliance with the License. 6e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * You may obtain a copy of the License at 7e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * 8e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * http://www.apache.org/licenses/LICENSE-2.0 9e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * 10e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * Unless required by applicable law or agreed to in writing, software 11e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * distributed under the License is distributed on an "AS IS" BASIS, 12e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * See the License for the specific language governing permissions and 14e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * limitations under the License. 15e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy */ 16e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 1785bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy#ifndef ANDROID_CUTILS_ATOMIC_INLINE_H 18e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy#define ANDROID_CUTILS_ATOMIC_INLINE_H 19e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 20e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy#ifdef __cplusplus 21e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guyextern "C" { 22e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy#endif 23bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy 24694b519ac647fe998fd396fe0784cc8e179aadc4Romain Guy/* 255cbbce535744b89df5ecea95de21ee3733298260Romain Guy * Inline declarations and macros for some special-purpose atomic 26121e2242565d5f09ad83a2d33ecd2225838802c5Romain Guy * operations. These are intended for rare circumstances where a 275cbbce535744b89df5ecea95de21ee3733298260Romain Guy * memory barrier needs to be issued inline rather than as a function 2885bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy * call. 2985bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy * 3051769a68a5cb34e9564740c6a854fcb93018789dRomain Guy * Most code should not use these. 31e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * 32e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * Anything that does include this file must set ANDROID_SMP to either 339d5316e3f56d138504565ff311145ac01621dff4Romain Guy * 0 or 1, indicating compilation for UP or SMP, respectively. 349d5316e3f56d138504565ff311145ac01621dff4Romain Guy * 359d5316e3f56d138504565ff311145ac01621dff4Romain Guy * Macros defined in this header: 369d5316e3f56d138504565ff311145ac01621dff4Romain Guy * 379d5316e3f56d138504565ff311145ac01621dff4Romain Guy * void ANDROID_MEMBAR_FULL(void) 389d5316e3f56d138504565ff311145ac01621dff4Romain Guy * Full memory barrier. Provides a compiler reordering barrier, and 39c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy * on SMP systems emits an appropriate instruction. 40c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy */ 41f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy 42c0ac193b9415680f0a69e20a3f5f22d16f8053beRomain Guy#if !defined(ANDROID_SMP) 43dda570201ac851dd85af3861f7e575721d3345daRomain Guy# error "Must define ANDROID_SMP before including atomic-inline.h" 44121e2242565d5f09ad83a2d33ecd2225838802c5Romain Guy#endif 45121e2242565d5f09ad83a2d33ecd2225838802c5Romain Guy 46121e2242565d5f09ad83a2d33ecd2225838802c5Romain Guy#if defined(__arm__) 47dda570201ac851dd85af3861f7e575721d3345daRomain Guy#include <cutils/atomic-arm.h> 48bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy#elif defined(__i386__) || defined(__x86_64__) 499d5316e3f56d138504565ff311145ac01621dff4Romain Guy#include <cutils/atomic-x86.h> 509d5316e3f56d138504565ff311145ac01621dff4Romain Guy#elif defined(__sh__) 519d5316e3f56d138504565ff311145ac01621dff4Romain Guy/* implementation is in atomic-android-sh.c */ 529d5316e3f56d138504565ff311145ac01621dff4Romain Guy#else 539d5316e3f56d138504565ff311145ac01621dff4Romain Guy#error atomic operations are unsupported 54026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy#endif 55026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy 56ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy#if ANDROID_SMP == 0 57c1396e93b6a5286a5183c00c781b62e940a12c1fRomain Guy#define ANDROID_MEMBAR_FULL android_compiler_barrier 58c1396e93b6a5286a5183c00c781b62e940a12c1fRomain Guy#else 59c1396e93b6a5286a5183c00c781b62e940a12c1fRomain Guy#define ANDROID_MEMBAR_FULL android_memory_barrier 60c1396e93b6a5286a5183c00c781b62e940a12c1fRomain Guy#endif 61bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy 62ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy#if ANDROID_SMP == 0 63ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy#define ANDROID_MEMBAR_STORE android_compiler_barrier 64026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy#else 65889f8d1403761d5668115ced6cbb3f767cfe966dRomain Guy#define ANDROID_MEMBAR_STORE android_memory_store_barrier 66889f8d1403761d5668115ced6cbb3f767cfe966dRomain Guy#endif 67889f8d1403761d5668115ced6cbb3f767cfe966dRomain Guy 68889f8d1403761d5668115ced6cbb3f767cfe966dRomain Guy#ifdef __cplusplus 69889f8d1403761d5668115ced6cbb3f767cfe966dRomain Guy} 70889f8d1403761d5668115ced6cbb3f767cfe966dRomain Guy#endif 71889f8d1403761d5668115ced6cbb3f767cfe966dRomain Guy 72889f8d1403761d5668115ced6cbb3f767cfe966dRomain Guy#endif /* ANDROID_CUTILS_ATOMIC_INLINE_H */ 73889f8d1403761d5668115ced6cbb3f767cfe966dRomain Guy