1 /* 2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef SOFTBUS_CPU_H 17 #define SOFTBUS_CPU_H 18 19 #ifdef __cplusplus 20 #if __cplusplus 21 extern "C" { 22 #endif 23 #endif 24 25 #ifdef _WIN32 26 #define BARRIER() MemoryBarrier() 27 #define MB() BARRIER() 28 #define WMB() BARRIER() 29 #define RMB() BARRIER() 30 #elif defined(__ICCARM__) || defined(__x86_64__) 31 #define MB() 32 #define WMB() 33 #define RMB() 34 #elif defined __linux__ || defined __LITEOS__ || defined __APPLE__ 35 #define DSB() __asm__ volatile("dsb" ::: "memory") 36 #ifdef __aarch64__ 37 #define DMB() __asm__ volatile("DMB ISHLD" : : : "memory") 38 #else 39 #define DMB() __asm__ volatile("dmb" ::: "memory") 40 #endif 41 #define ISB() __asm__ volatile("isb" ::: "memory") 42 #define BARRIER() __asm__ volatile("" ::: "memory") 43 44 #define MB() DMB() 45 #define WMB() DMB() 46 #define RMB() DMB() 47 #else 48 #define MB() 49 #define WMB() 50 #define RMB() 51 #endif 52 53 #ifdef __cplusplus 54 #if __cplusplus 55 } 56 #endif /* __cplusplus */ 57 #endif /* __cplusplus */ 58 #endif // SOFTBUS_CPU_H