From 4baea67e75507cdeff3ba1e45904f72cd6747846 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Thu, 5 May 2022 23:01:16 +1000 Subject: [PATCH] Common: Remove RwMutex It wasn't used, and if we need it, we can use std::shared_mutex. --- common/CMakeLists.txt | 2 - common/RwMutex.cpp | 114 ---------------------------------- common/RwMutex.h | 90 --------------------------- common/common.vcxproj | 2 - common/common.vcxproj.filters | 6 -- 5 files changed, 214 deletions(-) delete mode 100644 common/RwMutex.cpp delete mode 100644 common/RwMutex.h diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 123a425148..c8416d9dfc 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -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 diff --git a/common/RwMutex.cpp b/common/RwMutex.cpp deleted file mode 100644 index 1118378ab4..0000000000 --- a/common/RwMutex.cpp +++ /dev/null @@ -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 . - */ - -#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; -} diff --git a/common/RwMutex.h b/common/RwMutex.h deleted file mode 100644 index a3006e5a3a..0000000000 --- a/common/RwMutex.h +++ /dev/null @@ -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 . - */ - -#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 diff --git a/common/common.vcxproj b/common/common.vcxproj index da60a48a7e..bab7b615ec 100644 --- a/common/common.vcxproj +++ b/common/common.vcxproj @@ -99,7 +99,6 @@ - @@ -177,7 +176,6 @@ - diff --git a/common/common.vcxproj.filters b/common/common.vcxproj.filters index 7d77cee78a..48be9dec75 100644 --- a/common/common.vcxproj.filters +++ b/common/common.vcxproj.filters @@ -67,9 +67,6 @@ Source Files - - Source Files - Source Files @@ -291,9 +288,6 @@ Header Files - - Header Files - Header Files