1 /* 2 * Copyright (c) 2020 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 FRAMEWORKS_APP_ADAPTER_H 17 #define FRAMEWORKS_APP_ADAPTER_H 18 19 #ifdef __cplusplus 20 #define EXTERNC extern "C" 21 #else 22 #define EXTERNC 23 #endif 24 25 #ifndef __LITEOS_M__ 26 // memory operator define 27 #include <stdlib.h> 28 29 #include "ohos_errno.h" 30 #include "ohos_types.h" 31 32 #define AdapterMalloc(a) malloc(a) 33 #define AdapterFree(a) \ 34 do { \ 35 if ((a) != nullptr) { \ 36 (void) free((void *)(a)); \ 37 a = nullptr; \ 38 } \ 39 } while (0) 40 41 // mutex operation define 42 #define MutexDelete(a) pthread_mutex_destroy(a) 43 #define MutexAcquire(a, b) pthread_mutex_lock(a) 44 #define MutexRelease(a) pthread_mutex_unlock(a) 45 46 #else // __LITEOS_M__ 47 #include "stdint.h" 48 #include "ohos_mem_pool.h" 49 50 const unsigned int ERROR_SLEEP_TIMES = 300; 51 const unsigned int RETRY_TIMES = 10; 52 #define AdapterMalloc(a) OhosMalloc(MEM_TYPE_APPFMK_LSRAM, a) 53 #define AdapterFree(a) \ 54 do { \ 55 if (a != nullptr) { \ 56 (void) OhosFree((void *)a); \ 57 a = nullptr; \ 58 } \ 59 } while (0) 60 61 #define UI_Malloc(a) OhosMalloc(MEM_TYPE_APPFMK, a) 62 #define UI_Free(a) \ 63 do { \ 64 if (a != nullptr) { \ 65 (void) OhosFree((void *)a); \ 66 a = nullptr; \ 67 } \ 68 } while (0) 69 70 #define Malloc(a) malloc(a) 71 #define Free(a) \ 72 do { \ 73 if (a != nullptr) { \ 74 (void) free((void *)a); \ 75 a = nullptr; \ 76 } \ 77 } while (0) 78 79 #define RecordAbiityInfoEvt(code1) 80 #define MutexDelete(a) osMutexDelete(a) 81 #define MutexAcquire(a, b) osMutexAcquire(a, b) 82 #define MutexRelease(a) osMutexRelease(a) 83 #define SvrFree AdapterFree 84 #define SvrMalloc AdapterMalloc 85 86 #endif // APP_PLATFORM_WATCHGT 87 #endif // FRAMEWORKS_APP_ADAPTER_H