FileSystem: Don't use POSIX locks on Android
Requires SDK 24, and it's pointless anyway.
This commit is contained in:
parent
b814666134
commit
2e6deca76f
|
@ -2790,7 +2790,7 @@ bool FileSystem::SetPathCompression(const char* path, bool enable)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifdef HAS_POSIX_FILE_LOCK
|
||||||
|
|
||||||
static bool SetLock(int fd, bool lock, bool block, Error* error)
|
static bool SetLock(int fd, bool lock, bool block, Error* error)
|
||||||
{
|
{
|
||||||
|
|
|
@ -155,7 +155,12 @@ bool CommitAtomicRenamedFile(AtomicRenamedFile& file, Error* error);
|
||||||
void DiscardAtomicRenamedFile(AtomicRenamedFile& file);
|
void DiscardAtomicRenamedFile(AtomicRenamedFile& file);
|
||||||
|
|
||||||
/// Abstracts a POSIX file lock.
|
/// 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
|
class POSIXLock
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -175,6 +180,7 @@ public:
|
||||||
private:
|
private:
|
||||||
int m_fd;
|
int m_fd;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::optional<DynamicHeapArray<u8>> ReadBinaryFile(const char* path, Error* error = nullptr);
|
std::optional<DynamicHeapArray<u8>> ReadBinaryFile(const char* path, Error* error = nullptr);
|
||||||
|
|
|
@ -776,7 +776,7 @@ void GameList::Refresh(bool invalidate_cache, bool only_cache, ProgressCallback*
|
||||||
if (!cache_file)
|
if (!cache_file)
|
||||||
ERROR_LOG("Failed to open game list cache: {}", error.GetDescription());
|
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.
|
// Lock cache file for multi-instance on Linux. Implicitly done on Windows.
|
||||||
std::optional<FileSystem::POSIXLock> cache_file_lock;
|
std::optional<FileSystem::POSIXLock> cache_file_lock;
|
||||||
if (cache_file)
|
if (cache_file)
|
||||||
|
@ -1122,7 +1122,7 @@ GameList::PlayedTimeMap GameList::LoadPlayedTimeMap(const std::string& path)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifdef HAS_POSIX_FILE_LOCK
|
||||||
FileSystem::POSIXLock flock(fp.get());
|
FileSystem::POSIXLock flock(fp.get());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1159,7 +1159,7 @@ GameList::PlayedTimeEntry GameList::UpdatePlayedTimeFile(const std::string& path
|
||||||
return new_entry;
|
return new_entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifdef HAS_POSIX_FILE_LOCK
|
||||||
FileSystem::POSIXLock flock(fp.get());
|
FileSystem::POSIXLock flock(fp.get());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1726,7 +1726,7 @@ void GameList::ReloadMemcardTimestampCache()
|
||||||
if (!fp)
|
if (!fp)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifdef HAS_POSIX_FILE_LOCK
|
||||||
FileSystem::POSIXLock lock(fp.get());
|
FileSystem::POSIXLock lock(fp.get());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1856,7 +1856,7 @@ bool GameList::UpdateMemcardTimestampCache(const MemcardTimestampCacheEntry& ent
|
||||||
if (!fp)
|
if (!fp)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifdef HAS_POSIX_FILE_LOCK
|
||||||
FileSystem::POSIXLock lock(fp.get());
|
FileSystem::POSIXLock lock(fp.get());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -17,12 +17,6 @@
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <tuple>
|
#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 OpenGLPipeline;
|
||||||
class OpenGLStreamBuffer;
|
class OpenGLStreamBuffer;
|
||||||
class OpenGLTexture;
|
class OpenGLTexture;
|
||||||
|
@ -239,7 +233,7 @@ private:
|
||||||
bool m_timestamp_query_started = false;
|
bool m_timestamp_query_started = false;
|
||||||
|
|
||||||
std::FILE* m_pipeline_disk_cache_file = nullptr;
|
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;
|
FileSystem::POSIXLock m_pipeline_disk_cache_file_lock;
|
||||||
#endif
|
#endif
|
||||||
u32 m_pipeline_disk_cache_data_end = 0;
|
u32 m_pipeline_disk_cache_data_end = 0;
|
||||||
|
|
|
@ -765,7 +765,7 @@ bool OpenGLDevice::OpenPipelineCache(const std::string& path, Error* error)
|
||||||
if (!fp)
|
if (!fp)
|
||||||
return false;
|
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.
|
// Unix doesn't prevent concurrent write access, need to explicitly lock it.
|
||||||
FileSystem::POSIXLock fp_lock(fp.get(), true, error);
|
FileSystem::POSIXLock fp_lock(fp.get(), true, error);
|
||||||
if (!fp_lock.IsLocked())
|
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());
|
VERBOSE_LOG("Read {} programs from disk cache.", m_program_cache.size());
|
||||||
m_pipeline_disk_cache_file = fp.release();
|
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);
|
m_pipeline_disk_cache_file_lock = std::move(fp_lock);
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
|
@ -855,7 +855,7 @@ bool OpenGLDevice::OpenPipelineCache(const std::string& path, Error* error)
|
||||||
|
|
||||||
bool OpenGLDevice::CreatePipelineCache(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);
|
m_pipeline_disk_cache_file = FileSystem::OpenCFile(path.c_str(), "w+b", error);
|
||||||
if (!m_pipeline_disk_cache_file)
|
if (!m_pipeline_disk_cache_file)
|
||||||
return false;
|
return false;
|
||||||
|
@ -1015,7 +1015,7 @@ bool OpenGLDevice::DiscardPipelineCache()
|
||||||
if (!FileSystem::FTruncate64(m_pipeline_disk_cache_file, 0, &error))
|
if (!FileSystem::FTruncate64(m_pipeline_disk_cache_file, 0, &error))
|
||||||
{
|
{
|
||||||
ERROR_LOG("Failed to truncate pipeline cache: {}", error.GetDescription());
|
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();
|
m_pipeline_disk_cache_file_lock.Unlock();
|
||||||
#endif
|
#endif
|
||||||
std::fclose(m_pipeline_disk_cache_file);
|
std::fclose(m_pipeline_disk_cache_file);
|
||||||
|
@ -1031,7 +1031,7 @@ bool OpenGLDevice::DiscardPipelineCache()
|
||||||
bool OpenGLDevice::ClosePipelineCache(const std::string& filename, Error* error)
|
bool OpenGLDevice::ClosePipelineCache(const std::string& filename, Error* error)
|
||||||
{
|
{
|
||||||
const auto close_cache = [this]() {
|
const auto close_cache = [this]() {
|
||||||
#ifdef OPENGL_PIPELINE_CACHE_NEEDS_LOCK
|
#ifdef HAS_POSIX_FILE_LOCK
|
||||||
m_pipeline_disk_cache_file_lock.Unlock();
|
m_pipeline_disk_cache_file_lock.Unlock();
|
||||||
#endif
|
#endif
|
||||||
std::fclose(m_pipeline_disk_cache_file);
|
std::fclose(m_pipeline_disk_cache_file);
|
||||||
|
|
Loading…
Reference in New Issue