1 /* 2 * Copyright (c) 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 UTILS_INCLUDE_SYNC_FENCE_H 17 #define UTILS_INCLUDE_SYNC_FENCE_H 18 19 #include <string> 20 #include <refbase.h> 21 #include <unique_fd.h> 22 23 namespace OHOS { 24 25 class SyncFence : public RefBase { 26 public: 27 explicit SyncFence(int32_t fenceFd); 28 /* When the SyncFence is destroyed, the fd will be closed in UniqueFd */ 29 virtual ~SyncFence(); 30 31 SyncFence(const SyncFence& rhs) = delete; 32 SyncFence& operator=(const SyncFence& rhs) = delete; 33 SyncFence(SyncFence&& rhs) = delete; 34 SyncFence& operator=(SyncFence&& rhs) = delete; 35 36 static const sptr<SyncFence> INVALID_FENCE; 37 int32_t Wait(uint32_t timeout); 38 static sptr<SyncFence> MergeFence(const std::string &name, 39 const sptr<SyncFence>& fence1, const sptr<SyncFence>& fence2); 40 int64_t SyncFileReadTimestamp(); 41 int32_t Dup() const; 42 43 /* this is dangerous, when you use it, do not operator the fd */ 44 int32_t Get() const; 45 46 private: 47 struct SyncFenceInfo { 48 char objName_[32]; 49 char driverName_[32]; 50 int32_t status_; 51 uint32_t flags_; 52 uint64_t timestampNs_; 53 }; 54 55 struct SyncFileInfo { 56 char name_[32]; 57 int32_t status_; 58 uint32_t flags_; 59 uint32_t numFences_; 60 uint32_t pad_; 61 uint64_t syncFenceInfo_; 62 }; 63 64 UniqueFd fenceFd_; 65 }; 66 67 } 68 69 #endif // UTILS_INCLUDE_SYNC_FENCE_H