1 /* 2 * Copyright (c) 2025 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 #include "native_fence.h" 17 #include "sync_fence.h" 18 19 using namespace OHOS; 20 OH_NativeFence_Wait(int fenceFd,uint32_t timeout)21bool OH_NativeFence_Wait(int fenceFd, uint32_t timeout) 22 { 23 if (fenceFd < 0 || timeout == 0) { 24 return false; 25 } 26 int dupFd = dup(fenceFd); 27 if (dupFd < 0) { 28 return false; 29 } 30 sptr<SyncFence> fence = new SyncFence(dupFd); 31 if (fence == nullptr) { 32 close(dupFd); 33 return false; 34 } 35 36 bool result = fence->Wait(timeout) == 0 ? true : false; 37 return result; 38 } 39 OH_NativeFence_WaitForever(int fenceFd)40bool OH_NativeFence_WaitForever(int fenceFd) 41 { 42 if (fenceFd < 0) { 43 return false; 44 } 45 int dupFd = dup(fenceFd); 46 if (dupFd < 0) { 47 return false; 48 } 49 sptr<SyncFence> fence = new SyncFence(dupFd); 50 if (fence == nullptr) { 51 close(dupFd); 52 return false; 53 } 54 55 bool result = fence->Wait(-1) == 0 ? true : false; 56 return result; 57 } 58 OH_NativeFence_IsValid(int fenceFd)59bool OH_NativeFence_IsValid(int fenceFd) 60 { 61 if (fenceFd < 0) { 62 return false; 63 } 64 65 return true; 66 } 67 OH_NativeFence_Close(int fenceFd)68void OH_NativeFence_Close(int fenceFd) 69 { 70 if (fenceFd < 0) { 71 return; 72 } 73 74 close(fenceFd); 75 }