Debian Codegraph @

src/gfxstream/guest/platform/kumquat/VirtGpuKumquatSync.cpp

raw
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
12 VirtGpuKumquatSyncHelper::VirtGpuKumquatSyncHelper() {}
13
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
35 int VirtGpuKumquatSyncHelper::dup(int syncFd) { return ::dup(syncFd); }
36
37 void VirtGpuKumquatSyncHelper::debugPrint(int syncFd) { return; }
38
39 int VirtGpuKumquatSyncHelper::close(int syncFd) { return ::close(syncFd); }
40
41 SyncHelper* kumquatCreateSyncHelper() { return new VirtGpuKumquatSyncHelper(); }
42
43 } // namespace gfxstream