From 2e6deca76fd5999145542263013d1527c3dd47de Mon Sep 17 00:00:00 2001 From: Stenzek Date: Tue, 10 Dec 2024 01:04:33 +1000 Subject: [PATCH] FileSystem: Don't use POSIX locks on Android Requires SDK 24, and it's pointless anyway. --- src/common/file_system.cpp | 2 +- src/common/file_system.h | 8 +++++++- src/core/game_list.cpp | 10 +++++----- src/util/opengl_device.h | 8 +------- src/util/opengl_pipeline.cpp | 10 +++++----- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/common/file_system.cpp b/src/common/file_system.cpp index c888cc8af9..7f4dda7e53 100644 --- a/src/common/file_system.cpp +++ b/src/common/file_system.cpp @@ -2790,7 +2790,7 @@ bool FileSystem::SetPathCompression(const char* path, bool enable) #endif -#ifndef _WIN32 +#ifdef HAS_POSIX_FILE_LOCK static bool SetLock(int fd, bool lock, bool block, Error* error) { diff --git a/src/common/file_system.h b/src/common/file_system.h index c87c1d6586..654fa28e23 100644 --- a/src/common/file_system.h +++ b/src/common/file_system.h @@ -155,7 +155,12 @@ bool CommitAtomicRenamedFile(AtomicRenamedFile& file, Error* error); void DiscardAtomicRenamedFile(AtomicRenamedFile& file); /// Abstracts a POSIX file lock. -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(__ANDROID__) +#define HAS_POSIX_FILE_LOCK 1 +#endif + +#ifdef HAS_POSIX_FILE_LOCK + class POSIXLock { public: @@ -175,6 +180,7 @@ class POSIXLock private: int m_fd; }; + #endif std::optional> ReadBinaryFile(const char* path, Error* error = nullptr); diff --git a/src/core/game_list.cpp b/src/core/game_list.cpp index 3f3520ed52..6b4246f543 100644 --- a/src/core/game_list.cpp +++ b/src/core/game_list.cpp @@ -776,7 +776,7 @@ void GameList::Refresh(bool invalidate_cache, bool only_cache, ProgressCallback* if (!cache_file) ERROR_LOG("Failed to open game list cache: {}", error.GetDescription()); -#ifndef _WIN32 +#ifdef HAS_POSIX_FILE_LOCK // Lock cache file for multi-instance on Linux. Implicitly done on Windows. std::optional cache_file_lock; if (cache_file) @@ -1122,7 +1122,7 @@ GameList::PlayedTimeMap GameList::LoadPlayedTimeMap(const std::string& path) return ret; } -#ifndef _WIN32 +#ifdef HAS_POSIX_FILE_LOCK FileSystem::POSIXLock flock(fp.get()); #endif @@ -1159,7 +1159,7 @@ GameList::PlayedTimeEntry GameList::UpdatePlayedTimeFile(const std::string& path return new_entry; } -#ifndef _WIN32 +#ifdef HAS_POSIX_FILE_LOCK FileSystem::POSIXLock flock(fp.get()); #endif @@ -1726,7 +1726,7 @@ void GameList::ReloadMemcardTimestampCache() if (!fp) return; -#ifndef _WIN32 +#ifdef HAS_POSIX_FILE_LOCK FileSystem::POSIXLock lock(fp.get()); #endif @@ -1856,7 +1856,7 @@ bool GameList::UpdateMemcardTimestampCache(const MemcardTimestampCacheEntry& ent if (!fp) return false; -#ifndef _WIN32 +#ifdef HAS_POSIX_FILE_LOCK FileSystem::POSIXLock lock(fp.get()); #endif diff --git a/src/util/opengl_device.h b/src/util/opengl_device.h index fa1cae9c99..4cf1be9500 100644 --- a/src/util/opengl_device.h +++ b/src/util/opengl_device.h @@ -17,12 +17,6 @@ #include #include -// Unix doesn't prevent concurrent write access, need to explicitly lock the pipeline cache. -// Don't worry about Android, it's not like you can run one more than one instance of the app there... -#if !defined(_WIN32) && !defined(__ANDROID__) -#define OPENGL_PIPELINE_CACHE_NEEDS_LOCK 1 -#endif - class OpenGLPipeline; class OpenGLStreamBuffer; class OpenGLTexture; @@ -239,7 +233,7 @@ class OpenGLDevice final : public GPUDevice bool m_timestamp_query_started = false; std::FILE* m_pipeline_disk_cache_file = nullptr; -#ifdef OPENGL_PIPELINE_CACHE_NEEDS_LOCK +#ifdef HAS_POSIX_FILE_LOCK FileSystem::POSIXLock m_pipeline_disk_cache_file_lock; #endif u32 m_pipeline_disk_cache_data_end = 0; diff --git a/src/util/opengl_pipeline.cpp b/src/util/opengl_pipeline.cpp index ec31f4147a..35762c5ea5 100644 --- a/src/util/opengl_pipeline.cpp +++ b/src/util/opengl_pipeline.cpp @@ -765,7 +765,7 @@ bool OpenGLDevice::OpenPipelineCache(const std::string& path, Error* error) if (!fp) return false; -#ifdef OPENGL_PIPELINE_CACHE_NEEDS_LOCK +#ifdef HAS_POSIX_FILE_LOCK // Unix doesn't prevent concurrent write access, need to explicitly lock it. FileSystem::POSIXLock fp_lock(fp.get(), true, error); if (!fp_lock.IsLocked()) @@ -847,7 +847,7 @@ bool OpenGLDevice::OpenPipelineCache(const std::string& path, Error* error) VERBOSE_LOG("Read {} programs from disk cache.", m_program_cache.size()); m_pipeline_disk_cache_file = fp.release(); -#ifdef OPENGL_PIPELINE_CACHE_NEEDS_LOCK +#ifdef HAS_POSIX_FILE_LOCK m_pipeline_disk_cache_file_lock = std::move(fp_lock); #endif return true; @@ -855,7 +855,7 @@ bool OpenGLDevice::OpenPipelineCache(const std::string& path, Error* error) bool OpenGLDevice::CreatePipelineCache(const std::string& path, Error* error) { -#ifndef OPENGL_PIPELINE_CACHE_NEEDS_LOCK +#ifndef HAS_POSIX_FILE_LOCK m_pipeline_disk_cache_file = FileSystem::OpenCFile(path.c_str(), "w+b", error); if (!m_pipeline_disk_cache_file) return false; @@ -1015,7 +1015,7 @@ bool OpenGLDevice::DiscardPipelineCache() if (!FileSystem::FTruncate64(m_pipeline_disk_cache_file, 0, &error)) { ERROR_LOG("Failed to truncate pipeline cache: {}", error.GetDescription()); -#ifdef OPENGL_PIPELINE_CACHE_NEEDS_LOCK +#ifdef HAS_POSIX_FILE_LOCK m_pipeline_disk_cache_file_lock.Unlock(); #endif std::fclose(m_pipeline_disk_cache_file); @@ -1031,7 +1031,7 @@ bool OpenGLDevice::DiscardPipelineCache() bool OpenGLDevice::ClosePipelineCache(const std::string& filename, Error* error) { const auto close_cache = [this]() { -#ifdef OPENGL_PIPELINE_CACHE_NEEDS_LOCK +#ifdef HAS_POSIX_FILE_LOCK m_pipeline_disk_cache_file_lock.Unlock(); #endif std::fclose(m_pipeline_disk_cache_file);