1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <utils/String8.h> 20 21 #include "unique_fd.h" 22 23 namespace android { 24 namespace automotive { 25 namespace evs { 26 namespace V1_1 { 27 namespace implementation { 28 29 // This is a simple C++ wrapper around the sw_sync interface. It is used to 30 // create and maintain sync fences created from a timeline. 31 class UniqueFence { 32 public: 33 UniqueFence(); 34 explicit UniqueFence(int fd); 35 36 UniqueFence(UniqueFence&&); 37 UniqueFence& operator=(UniqueFence&&); 38 39 // Destroy the current fence. 40 void Reset(); 41 42 // Duplicate the fence. 43 UniqueFence Dup() const; 44 45 // Gets the descriptor 46 int Get() const; 47 48 // Gets an unowned duplicate of the fence descriptor. 49 int GetUnowned() const; 50 51 // Returns true if the fence is set to a valid descriptor. False otherwise. 52 explicit operator bool() const; 53 54 // Waits on the fence for the indicated amount of time in milliseconds. The 55 // default value of -1 means to wait forever. 56 int Wait(int wait_time_ms = -1); 57 58 // Gets a string containing debug information for the fence. 59 void GetDebugStateDump(String8& result) const; 60 61 // Creates a new fence that signals when both input fences are signaled. Note 62 // that it is possible to merge multiple fences this way. 63 static UniqueFence Merge(const char* name, const UniqueFence& fence1, 64 const UniqueFence& fence2); 65 66 private: 67 // The fence file descriptor 68 UniqueFd fd_; 69 }; 70 71 } // namespace implementation 72 } // namespace V1_1 73 } // namespace evs 74 } // namespace automotive 75 } // namespace android 76 77