FileSystem: Don't use POSIX locks on Android

Requires SDK 24, and it's pointless anyway.
This commit is contained in:
Stenzek 2024-12-10 01:04:33 +10:00
parent b814666134
commit 2e6deca76f
No known key found for this signature in database
5 changed files with 19 additions and 19 deletions

View File

@ -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)
{

View File

@ -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 @@ public:
private:
int m_fd;
};
#endif
std::optional<DynamicHeapArray<u8>> ReadBinaryFile(const char* path, Error* error = nullptr);

View File

@ -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<FileSystem::POSIXLock> 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

View File

@ -17,12 +17,6 @@
#include <string_view>
#include <tuple>
// 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 @@ private:
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;

View File

@ -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);