Common: Remove RwMutex

It wasn't used, and if we need it, we can use std::shared_mutex.
This commit is contained in:
Connor McLaughlin 2022-05-05 23:01:16 +10:00 committed by refractionpcsx2
parent 1e8332f36a
commit 4baea67e75
5 changed files with 0 additions and 214 deletions

View File

@ -28,7 +28,6 @@ target_sources(common PRIVATE
Perf.cpp
ProgressCallback.cpp
pxTranslate.cpp
RwMutex.cpp
Semaphore.cpp
SettingsWrapper.cpp
StringHelpers.cpp
@ -85,7 +84,6 @@ target_sources(common PRIVATE
ProgressCallback.h
pxForwardDefs.h
RedtapeWindows.h
RwMutex.h
SafeArray.h
ScopedGuard.h
SettingsInterface.h

View File

@ -1,114 +0,0 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2010 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "common/RwMutex.h"
// --------------------------------------------------------------------------------------
// RwMutex
// --------------------------------------------------------------------------------------
Threading::RwMutex::RwMutex()
{
pthread_rwlock_init(&m_rwlock, NULL);
}
Threading::RwMutex::~RwMutex()
{
pthread_rwlock_destroy(&m_rwlock);
}
void Threading::RwMutex::AcquireRead()
{
pthread_rwlock_rdlock(&m_rwlock);
}
void Threading::RwMutex::AcquireWrite()
{
pthread_rwlock_wrlock(&m_rwlock);
}
bool Threading::RwMutex::TryAcquireRead()
{
return pthread_rwlock_tryrdlock(&m_rwlock) != EBUSY;
}
bool Threading::RwMutex::TryAcquireWrite()
{
return pthread_rwlock_trywrlock(&m_rwlock) != EBUSY;
}
void Threading::RwMutex::Release()
{
pthread_rwlock_unlock(&m_rwlock);
}
// --------------------------------------------------------------------------------------
//
// --------------------------------------------------------------------------------------
Threading::BaseScopedReadWriteLock::~BaseScopedReadWriteLock()
{
if (m_IsLocked)
m_lock.Release();
}
// Provides manual unlocking of a scoped lock prior to object destruction.
void Threading::BaseScopedReadWriteLock::Release()
{
if (!m_IsLocked)
return;
m_IsLocked = false;
m_lock.Release();
}
// --------------------------------------------------------------------------------------
// ScopedReadLock / ScopedWriteLock
// --------------------------------------------------------------------------------------
Threading::ScopedReadLock::ScopedReadLock(RwMutex& locker)
: BaseScopedReadWriteLock(locker)
{
m_IsLocked = true;
m_lock.AcquireRead();
}
// provides manual locking of a scoped lock, to re-lock after a manual unlocking.
void Threading::ScopedReadLock::Acquire()
{
if (m_IsLocked)
return;
m_lock.AcquireRead();
m_IsLocked = true;
}
Threading::ScopedWriteLock::ScopedWriteLock(RwMutex& locker)
: BaseScopedReadWriteLock(locker)
{
m_IsLocked = true;
m_lock.AcquireWrite();
}
// provides manual locking of a scoped lock, to re-lock after a manual unlocking.
void Threading::ScopedWriteLock::Acquire()
{
if (m_IsLocked)
return;
m_lock.AcquireWrite();
m_IsLocked = true;
}
// Special constructor used by ScopedTryLock
Threading::ScopedWriteLock::ScopedWriteLock(RwMutex& locker, bool isTryLock)
: BaseScopedReadWriteLock(locker)
{
//m_IsLocked = isTryLock ? m_lock.TryAcquireWrite() : false;
}

View File

@ -1,90 +0,0 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2010 PCSX2 Dev Team
*
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "common/Threading.h"
namespace Threading
{
// --------------------------------------------------------------------------------------
// RwMutex
// --------------------------------------------------------------------------------------
class RwMutex
{
DeclareNoncopyableObject(RwMutex);
protected:
pthread_rwlock_t m_rwlock;
public:
RwMutex();
virtual ~RwMutex();
virtual void AcquireRead();
virtual void AcquireWrite();
virtual bool TryAcquireRead();
virtual bool TryAcquireWrite();
virtual void Release();
};
// --------------------------------------------------------------------------------------
// BaseScopedReadWriteLock
// --------------------------------------------------------------------------------------
class BaseScopedReadWriteLock
{
DeclareNoncopyableObject(BaseScopedReadWriteLock);
protected:
RwMutex& m_lock;
bool m_IsLocked;
public:
BaseScopedReadWriteLock(RwMutex& locker)
: m_lock(locker)
{
}
virtual ~BaseScopedReadWriteLock();
void Release();
bool IsLocked() const { return m_IsLocked; }
};
// --------------------------------------------------------------------------------------
// ScopedReadLock / ScopedWriteLock
// --------------------------------------------------------------------------------------
class ScopedReadLock : public BaseScopedReadWriteLock
{
public:
ScopedReadLock(RwMutex& locker);
virtual ~ScopedReadLock() = default;
void Acquire();
};
class ScopedWriteLock : public BaseScopedReadWriteLock
{
public:
ScopedWriteLock(RwMutex& locker);
virtual ~ScopedWriteLock() = default;
void Acquire();
protected:
ScopedWriteLock(RwMutex& locker, bool isTryLock);
};
} // namespace Threading

View File

@ -99,7 +99,6 @@
<ClCompile Include="Windows\WinThreads.cpp" />
<ClCompile Include="Misc.cpp" />
<ClCompile Include="Mutex.cpp" />
<ClCompile Include="RwMutex.cpp" />
<ClCompile Include="Semaphore.cpp" />
<ClCompile Include="ThreadTools.cpp" />
<ClCompile Include="emitter\bmi.cpp" />
@ -177,7 +176,6 @@
<ClInclude Include="Vulkan\Util.h" />
<ClInclude Include="WindowInfo.h" />
<ClInclude Include="Threading.h" />
<ClInclude Include="RwMutex.h" />
<ClInclude Include="emitter\implement\bmi.h" />
<ClInclude Include="emitter\cpudetect_internal.h" />
<ClInclude Include="emitter\instructions.h" />

View File

@ -67,9 +67,6 @@
<ClCompile Include="pxTranslate.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="RwMutex.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Semaphore.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@ -291,9 +288,6 @@
<ClInclude Include="RedtapeWindows.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="RwMutex.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SafeArray.h">
<Filter>Header Files</Filter>
</ClInclude>