• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 #ifndef ANDROID_FENCE_H
18 #define ANDROID_FENCE_H
19 
20 #include <utils/RefBase.h>
21 #include <utils/String8.h>
22 
23 typedef int64_t nsecs_t;
24 
25 namespace android {
26 
27 class Fence : public LightRefBase<Fence> {
28 public:
Fence()29     Fence() {}
30 
Fence(int)31     Fence(int) {}
32 
33     static const sp<Fence> NO_FENCE;
34     static constexpr nsecs_t SIGNAL_TIME_PENDING = INT64_MAX;
35     static constexpr nsecs_t SIGNAL_TIME_INVALID = -1;
36 
merge(const char * name,const sp<Fence> & f1,const sp<Fence> & f2)37     static sp<Fence> merge(const char* name, const sp<Fence>& f1, const sp<Fence>& f2) {
38         return NO_FENCE;
39     }
40 
merge(const String8 & name,const sp<Fence> & f1,const sp<Fence> & f2)41     static sp<Fence> merge(const String8& name, const sp<Fence>& f1, const sp<Fence>& f2) {
42         return NO_FENCE;
43     }
44 
45     enum class Status {
46         Invalid,    // Fence is invalid
47         Unsignaled, // Fence is valid but has not yet signaled
48         Signaled,   // Fence is valid and has signaled
49     };
50 
wait(int timeout)51     status_t wait(int timeout) {
52         return OK;
53     }
54 
waitForever(const char * logname)55     status_t waitForever(const char* logname) {
56         return OK;
57     }
58 
dup()59     int dup() const {
60         return 0;
61     }
62 
getStatus()63     inline Status getStatus() {
64         // The sync_wait call underlying wait() has been measured to be
65         // significantly faster than the sync_fence_info call underlying
66         // getSignalTime(), which might otherwise appear to be the more obvious
67         // way to check whether a fence has signaled.
68         switch (wait(0)) {
69             case NO_ERROR:
70                 return Status::Signaled;
71             case -ETIME:
72                 return Status::Unsignaled;
73             default:
74                 return Status::Invalid;
75         }
76     }
77 };
78 
79 } // namespace android
80 
81 #endif // ANDROID_FENCE_H
82