xref: /aosp_15_r20/external/mesa3d/src/gfxstream/guest/platform/kumquat/VirtGpuKumquatSync.cpp (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright 2023 Google
3  * SPDX-License-Identifier: MIT
4  */
5 
6 #include "VirtGpuKumquatSync.h"
7 
8 #include <unistd.h>
9 
10 namespace gfxstream {
11 
VirtGpuKumquatSyncHelper()12 VirtGpuKumquatSyncHelper::VirtGpuKumquatSyncHelper() {}
13 
wait(int syncFd,int timeoutMilliseconds)14 int VirtGpuKumquatSyncHelper::wait(int syncFd, int timeoutMilliseconds) {
15     (void)timeoutMilliseconds;
16     // So far, syncfds are EventFd in the Kumquat layer. This may change
17     uint64_t count = 1;
18     ssize_t bytes_read = read(syncFd, &count, sizeof(count));
19 
20     if (bytes_read < 0) {
21         return bytes_read;
22     }
23 
24     // A successful read decrements the eventfd's counter to zero.  In
25     // case the eventfd is waited on again, or a dup is waited on, we
26     // have to write to the eventfd for the next read.
27     ssize_t bytes_written = write(syncFd, &count, sizeof(count));
28     if (bytes_written < 0) {
29         return bytes_written;
30     }
31 
32     return 0;
33 }
34 
dup(int syncFd)35 int VirtGpuKumquatSyncHelper::dup(int syncFd) { return ::dup(syncFd); }
36 
debugPrint(int syncFd)37 void VirtGpuKumquatSyncHelper::debugPrint(int syncFd) { return; }
38 
close(int syncFd)39 int VirtGpuKumquatSyncHelper::close(int syncFd) { return ::close(syncFd); }
40 
kumquatCreateSyncHelper()41 SyncHelper* kumquatCreateSyncHelper() { return new VirtGpuKumquatSyncHelper(); }
42 
43 }  // namespace gfxstream
44