Make controller button code thread-safe (#405)

* Refactor spinlock to meet Lockable requirements
* Input: Refactor button code and make it thread-safe
This commit is contained in:
Exzap 2022-10-23 15:47:42 +02:00 committed by GitHub
parent c40466f3a8
commit 028b3f7992
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 311 additions and 220 deletions

View file

@ -516,16 +516,16 @@ FSpinlock s_spinlockFetchShaderCache;
LatteFetchShader* LatteFetchShader::RegisterInCache(CacheHash fsHash)
{
s_spinlockFetchShaderCache.acquire();
s_spinlockFetchShaderCache.lock();
auto itr = s_fetchShaderByHash.find(fsHash);
if (itr != s_fetchShaderByHash.end())
{
LatteFetchShader* fs = itr->second;
s_spinlockFetchShaderCache.release();
s_spinlockFetchShaderCache.unlock();
return fs;
}
s_fetchShaderByHash.emplace(fsHash, this);
s_spinlockFetchShaderCache.release();
s_spinlockFetchShaderCache.unlock();
return nullptr;
}
@ -533,11 +533,11 @@ void LatteFetchShader::UnregisterInCache()
{
if (!m_isRegistered)
return;
s_spinlockFetchShaderCache.acquire();
s_spinlockFetchShaderCache.lock();
auto itr = s_fetchShaderByHash.find(m_cacheHash);
cemu_assert(itr == s_fetchShaderByHash.end());
s_fetchShaderByHash.erase(itr);
s_spinlockFetchShaderCache.release();
s_spinlockFetchShaderCache.unlock();
}
std::unordered_map<LatteFetchShader::CacheHash, LatteFetchShader*> LatteFetchShader::s_fetchShaderByHash;

View file

@ -1074,19 +1074,19 @@ void LatteBufferCache_notifyDCFlush(MPTR address, uint32 size)
uint32 firstPage = address / CACHE_PAGE_SIZE;
uint32 lastPage = (address + size - 1) / CACHE_PAGE_SIZE;
g_spinlockDCFlushQueue.acquire();
g_spinlockDCFlushQueue.lock();
for (uint32 i = firstPage; i <= lastPage; i++)
s_DCFlushQueue->Set(i);
g_spinlockDCFlushQueue.release();
g_spinlockDCFlushQueue.unlock();
}
void LatteBufferCache_processDCFlushQueue()
{
if (s_DCFlushQueue->Empty()) // quick check to avoid locking if there is no work to do
return;
g_spinlockDCFlushQueue.acquire();
g_spinlockDCFlushQueue.lock();
std::swap(s_DCFlushQueue, s_DCFlushQueueAlternate);
g_spinlockDCFlushQueue.release();
g_spinlockDCFlushQueue.unlock();
s_DCFlushQueueAlternate->ForAllAndClear([](uint32 index) {LatteBufferCache_invalidatePage(index * CACHE_PAGE_SIZE); });
}