mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-01 14:58:14 +00:00
Big mutex overhaul - remove our custom ones, make them non-recursive where possible
This commit is contained in:
1 parent
54f862cda6
commit
26a2d42731
75 files changed
+561
-882
No files matched your search
@@ -43,7 +43,7 @@ RamCachingFileLoader::~RamCachingFileLoader() {
|
||||
|
||||
bool RamCachingFileLoader::Exists() {
|
||||
if (exists_ == -1) {
|
||||
lock_guard guard(backendMutex_);
|
||||
std::lock_guard<std::mutex> guard(backendMutex_);
|
||||
exists_ = backend_->Exists() ? 1 : 0;
|
||||
}
|
||||
return exists_ == 1;
|
||||
@@ -51,7 +51,7 @@ bool RamCachingFileLoader::Exists() {
|
||||
|
||||
bool RamCachingFileLoader::ExistsFast() {
|
||||
if (exists_ == -1) {
|
||||
lock_guard guard(backendMutex_);
|
||||
std::lock_guard<std::mutex> guard(backendMutex_);
|
||||
return backend_->ExistsFast();
|
||||
}
|
||||
return exists_ == 1;
|
||||
@@ -59,7 +59,7 @@ bool RamCachingFileLoader::ExistsFast() {
|
||||
|
||||
bool RamCachingFileLoader::IsDirectory() {
|
||||
if (isDirectory_ == -1) {
|
||||
lock_guard guard(backendMutex_);
|
||||
std::lock_guard<std::mutex> guard(backendMutex_);
|
||||
isDirectory_ = backend_->IsDirectory() ? 1 : 0;
|
||||
}
|
||||
return isDirectory_ == 1;
|
||||
@@ -70,7 +70,7 @@ s64 RamCachingFileLoader::FileSize() {
|
||||
}
|
||||
|
||||
std::string RamCachingFileLoader::Path() const {
|
||||
lock_guard guard(backendMutex_);
|
||||
std::lock_guard<std::mutex> guard(backendMutex_);
|
||||
return backend_->Path();
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ void RamCachingFileLoader::Seek(s64 absolutePos) {
|
||||
size_t RamCachingFileLoader::ReadAt(s64 absolutePos, size_t bytes, void *data, Flags flags) {
|
||||
size_t readSize = 0;
|
||||
if (cache_ == nullptr || (flags & Flags::HINT_UNCACHED) != 0) {
|
||||
lock_guard guard(backendMutex_);
|
||||
std::lock_guard<std::mutex> guard(backendMutex_);
|
||||
readSize = backend_->ReadAt(absolutePos, bytes, data, flags);
|
||||
} else {
|
||||
readSize = ReadFromCache(absolutePos, bytes, data);
|
||||
@@ -104,7 +104,7 @@ size_t RamCachingFileLoader::ReadAt(s64 absolutePos, size_t bytes, void *data, F
|
||||
}
|
||||
|
||||
void RamCachingFileLoader::InitCache() {
|
||||
lock_guard guard(blocksMutex_);
|
||||
std::lock_guard<std::mutex> guard(blocksMutex_);
|
||||
u32 blockCount = (u32)((filesize_ + BLOCK_SIZE - 1) >> BLOCK_SHIFT);
|
||||
// Overallocate for the last block.
|
||||
cache_ = (u8 *)malloc((size_t)blockCount << BLOCK_SHIFT);
|
||||
@@ -117,7 +117,7 @@ void RamCachingFileLoader::InitCache() {
|
||||
|
||||
void RamCachingFileLoader::ShutdownCache() {
|
||||
{
|
||||
lock_guard guard(blocksMutex_);
|
||||
std::lock_guard<std::mutex> guard(blocksMutex_);
|
||||
// Try to have the thread stop.
|
||||
aheadRemaining_ = 0;
|
||||
}
|
||||
@@ -128,7 +128,7 @@ void RamCachingFileLoader::ShutdownCache() {
|
||||
sleep_ms(1);
|
||||
}
|
||||
|
||||
lock_guard guard(blocksMutex_);
|
||||
std::lock_guard<std::mutex> guard(blocksMutex_);
|
||||
blocks_.clear();
|
||||
if (cache_ != nullptr) {
|
||||
free(cache_);
|
||||
@@ -156,7 +156,7 @@ size_t RamCachingFileLoader::ReadFromCache(s64 pos, size_t bytes, void *data) {
|
||||
bytes = filesize_ - pos;
|
||||
}
|
||||
|
||||
lock_guard guard(blocksMutex_);
|
||||
std::lock_guard<std::mutex> guard(blocksMutex_);
|
||||
for (s64 i = cacheStartPos; i <= cacheEndPos; ++i) {
|
||||
if (blocks_[i] == 0) {
|
||||
return readSize;
|
||||
@@ -182,7 +182,7 @@ void RamCachingFileLoader::SaveIntoCache(s64 pos, size_t bytes, Flags flags) {
|
||||
|
||||
size_t blocksToRead = 0;
|
||||
{
|
||||
lock_guard guard(blocksMutex_);
|
||||
std::lock_guard<std::mutex> guard(blocksMutex_);
|
||||
for (s64 i = cacheStartPos; i <= cacheEndPos; ++i) {
|
||||
if (blocks_[i] == 0) {
|
||||
++blocksToRead;
|
||||
@@ -201,7 +201,7 @@ void RamCachingFileLoader::SaveIntoCache(s64 pos, size_t bytes, Flags flags) {
|
||||
// In case there was an error, let's not mark blocks that failed to read as read.
|
||||
u32 blocksActuallyRead = (u32)((bytesRead + BLOCK_SIZE - 1) >> BLOCK_SHIFT);
|
||||
{
|
||||
lock_guard guard(blocksMutex_);
|
||||
std::lock_guard<std::mutex> guard(blocksMutex_);
|
||||
|
||||
// In case they were simultaneously read.
|
||||
u32 blocksRead = 0;
|
||||
@@ -223,7 +223,7 @@ void RamCachingFileLoader::StartReadAhead(s64 pos) {
|
||||
return;
|
||||
}
|
||||
|
||||
lock_guard guard(blocksMutex_);
|
||||
std::lock_guard<std::mutex> guard(blocksMutex_);
|
||||
aheadPos_ = pos;
|
||||
if (aheadThread_) {
|
||||
// Already going.
|
||||
@@ -260,7 +260,7 @@ void RamCachingFileLoader::StartReadAhead(s64 pos) {
|
||||
}
|
||||
|
||||
u32 RamCachingFileLoader::NextAheadBlock() {
|
||||
lock_guard guard(blocksMutex_);
|
||||
std::lock_guard<std::mutex> guard(blocksMutex_);
|
||||
|
||||
// If we had an aheadPos_ set, start reading from there and go forward.
|
||||
u32 startFrom = (u32)(aheadPos_ >> BLOCK_SHIFT);
|
||||
|
||||
Reference in new issue
Block a user