From 0e8582d6da8ba91ef08fe8b7aca6f2f4d1d4b5ba Mon Sep 17 00:00:00 2001 From: Jason Macnak Date: Tue, 19 Sep 2023 13:21:41 -0700 Subject: [PATCH] Move SyncHelper to platform ... upcoming changes will add promote the emulated virtio gpu stack as a proper platform backend which will include the SyncHelper. Reviewed-by: Aaron Ruby Acked-by: Yonggang Luo Acked-by: Adam Jackson Part-of: --- src/gfxstream/guest/platform/include/Sync.h | 36 +++++++++++++ .../guest/platform/linux/LinuxSync.cpp | 50 +++++++++++++++++++ .../guest/platform/linux/LinuxSync.h | 32 ++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 src/gfxstream/guest/platform/include/Sync.h create mode 100644 src/gfxstream/guest/platform/linux/LinuxSync.cpp create mode 100644 src/gfxstream/guest/platform/linux/LinuxSync.h diff --git a/src/gfxstream/guest/platform/include/Sync.h b/src/gfxstream/guest/platform/include/Sync.h new file mode 100644 index 00000000000..3f7ae090c44 --- /dev/null +++ b/src/gfxstream/guest/platform/include/Sync.h @@ -0,0 +1,36 @@ +// Copyright 2023 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expresso or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include +#include + +namespace gfxstream { + +// Abstraction around libsync for testing. +class SyncHelper { + public: + virtual ~SyncHelper() {} + + virtual int wait(int syncFd, int timeoutMilliseconds) = 0; + + virtual int dup(int syncFd) = 0; + + virtual int close(int syncFd) = 0; +}; + +SyncHelper* createPlatformSyncHelper(); + +} // namespace gfxstream diff --git a/src/gfxstream/guest/platform/linux/LinuxSync.cpp b/src/gfxstream/guest/platform/linux/LinuxSync.cpp new file mode 100644 index 00000000000..7b0620d4fb3 --- /dev/null +++ b/src/gfxstream/guest/platform/linux/LinuxSync.cpp @@ -0,0 +1,50 @@ +/* + * Copyright 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "LinuxSync.h" + +#if defined(__ANDROID__) +#include +#endif +#include + +namespace gfxstream { + +LinuxSyncHelper::LinuxSyncHelper() {} + +int LinuxSyncHelper::wait(int syncFd, int timeoutMilliseconds) { +#if defined(__ANDROID__) + return sync_wait(syncFd, timeoutMilliseconds); +#else + (void)syncFd; + (void)timeoutMilliseconds; + return -1; +#endif +} + +int LinuxSyncHelper::dup(int syncFd) { + return ::dup(syncFd); +} + +int LinuxSyncHelper::close(int syncFd) { + return ::close(syncFd); +} + +SyncHelper* createPlatformSyncHelper() { + return new LinuxSyncHelper(); +} + +} // namespace gfxstream diff --git a/src/gfxstream/guest/platform/linux/LinuxSync.h b/src/gfxstream/guest/platform/linux/LinuxSync.h new file mode 100644 index 00000000000..d4434d71f3b --- /dev/null +++ b/src/gfxstream/guest/platform/linux/LinuxSync.h @@ -0,0 +1,32 @@ +// Copyright 2023 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expresso or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include "Sync.h" + +namespace gfxstream { + +class LinuxSyncHelper : public SyncHelper { + public: + LinuxSyncHelper(); + + int wait(int syncFd, int timeoutMilliseconds) override; + + int dup(int syncFd) override; + + int close(int syncFd) override; +}; + +} // namespace gfxstream