mirror of https://github.com/PCSX2/pcsx2.git
Misc: Replace use of Threading::Mutex with std::mutex in core code
This commit is contained in:
parent
a93829557b
commit
65e956a01c
|
@ -16,7 +16,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include "common/Threading.h"
|
#include <mutex>
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------
|
||||||
// EventSource< template EvtType >
|
// EventSource< template EvtType >
|
||||||
|
@ -41,7 +41,7 @@ protected:
|
||||||
ListenerList m_cache_copy;
|
ListenerList m_cache_copy;
|
||||||
bool m_cache_valid;
|
bool m_cache_valid;
|
||||||
|
|
||||||
Threading::Mutex m_listeners_lock;
|
std::mutex m_listeners_lock;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EventSource()
|
EventSource()
|
||||||
|
|
|
@ -14,15 +14,14 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "common/Pcsx2Defs.h"
|
||||||
#include "common/Threading.h"
|
#include "common/Exceptions.h"
|
||||||
|
#include "common/Console.h"
|
||||||
using Threading::ScopedLock;
|
|
||||||
|
|
||||||
template <typename ListenerType>
|
template <typename ListenerType>
|
||||||
typename EventSource<ListenerType>::ListenerIterator EventSource<ListenerType>::Add(ListenerType& listener)
|
typename EventSource<ListenerType>::ListenerIterator EventSource<ListenerType>::Add(ListenerType& listener)
|
||||||
{
|
{
|
||||||
ScopedLock locker(m_listeners_lock);
|
std::unique_lock locker(m_listeners_lock);
|
||||||
|
|
||||||
// Check for duplicates before adding the event.
|
// Check for duplicates before adding the event.
|
||||||
if (IsDebugBuild)
|
if (IsDebugBuild)
|
||||||
|
@ -41,7 +40,7 @@ typename EventSource<ListenerType>::ListenerIterator EventSource<ListenerType>::
|
||||||
template <typename ListenerType>
|
template <typename ListenerType>
|
||||||
void EventSource<ListenerType>::Remove(ListenerType& listener)
|
void EventSource<ListenerType>::Remove(ListenerType& listener)
|
||||||
{
|
{
|
||||||
ScopedLock locker(m_listeners_lock);
|
std::unique_lock locker(m_listeners_lock);
|
||||||
m_cache_valid = false;
|
m_cache_valid = false;
|
||||||
m_listeners.remove(&listener);
|
m_listeners.remove(&listener);
|
||||||
}
|
}
|
||||||
|
@ -49,7 +48,7 @@ void EventSource<ListenerType>::Remove(ListenerType& listener)
|
||||||
template <typename ListenerType>
|
template <typename ListenerType>
|
||||||
void EventSource<ListenerType>::Remove(const ListenerIterator& listenerHandle)
|
void EventSource<ListenerType>::Remove(const ListenerIterator& listenerHandle)
|
||||||
{
|
{
|
||||||
ScopedLock locker(m_listeners_lock);
|
std::unique_lock locker(m_listeners_lock);
|
||||||
m_cache_valid = false;
|
m_cache_valid = false;
|
||||||
m_listeners.erase(listenerHandle);
|
m_listeners.erase(listenerHandle);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,13 +14,15 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
#include <wx/thread.h>
|
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "common/PageFaultSource.h"
|
#include "common/PageFaultSource.h"
|
||||||
|
#include "common/Console.h"
|
||||||
|
#include "common/Exceptions.h"
|
||||||
|
#include "common/StringHelpers.h"
|
||||||
|
|
||||||
// Apple uses the MAP_ANON define instead of MAP_ANONYMOUS, but they mean
|
// Apple uses the MAP_ANON define instead of MAP_ANONYMOUS, but they mean
|
||||||
// the same thing.
|
// the same thing.
|
||||||
|
@ -55,7 +57,7 @@ static void SysPageFaultSignalFilter(int signal, siginfo_t* siginfo, void*)
|
||||||
// Note: This signal can be accessed by the EE or MTVU thread
|
// Note: This signal can be accessed by the EE or MTVU thread
|
||||||
// Source_PageFault is a global variable with its own state information
|
// Source_PageFault is a global variable with its own state information
|
||||||
// so for now we lock this exception code unless someone can fix this better...
|
// so for now we lock this exception code unless someone can fix this better...
|
||||||
Threading::ScopedLock lock(PageFault_Mutex);
|
std::unique_lock lock(PageFault_Mutex);
|
||||||
|
|
||||||
Source_PageFault->Dispatch(PageFaultInfo((uptr)siginfo->si_addr & ~m_pagemask));
|
Source_PageFault->Dispatch(PageFaultInfo((uptr)siginfo->si_addr & ~m_pagemask));
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,10 @@
|
||||||
|
|
||||||
#include "EventSource.h"
|
#include "EventSource.h"
|
||||||
#include "General.h"
|
#include "General.h"
|
||||||
|
#include "Assertions.h"
|
||||||
|
#include "Dependencies.h"
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
struct PageFaultInfo
|
struct PageFaultInfo
|
||||||
{
|
{
|
||||||
|
@ -314,6 +317,5 @@ extern long __stdcall SysPageFaultExceptionFilter(struct _EXCEPTION_POINTERS* ep
|
||||||
extern void pxInstallSignalHandler();
|
extern void pxInstallSignalHandler();
|
||||||
extern void _platform_InstallSignalHandler();
|
extern void _platform_InstallSignalHandler();
|
||||||
|
|
||||||
#include "Threading.h"
|
|
||||||
extern SrcType_PageFault* Source_PageFault;
|
extern SrcType_PageFault* Source_PageFault;
|
||||||
extern Threading::Mutex PageFault_Mutex;
|
extern std::mutex PageFault_Mutex;
|
||||||
|
|
|
@ -13,17 +13,15 @@
|
||||||
* If not, see <http://www.gnu.org/licenses/>.
|
* If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __WXMSW__
|
|
||||||
#include <wx/thread.h>
|
|
||||||
#endif
|
|
||||||
#include "common/PageFaultSource.h"
|
#include "common/PageFaultSource.h"
|
||||||
#include "common/EventSource.inl"
|
#include "common/EventSource.inl"
|
||||||
#include "common/MemsetFast.inl"
|
#include "common/MemsetFast.inl"
|
||||||
|
#include "common/Console.h"
|
||||||
|
|
||||||
template class EventSource<IEventListener_PageFault>;
|
template class EventSource<IEventListener_PageFault>;
|
||||||
|
|
||||||
SrcType_PageFault* Source_PageFault = NULL;
|
SrcType_PageFault* Source_PageFault = NULL;
|
||||||
Threading::Mutex PageFault_Mutex;
|
std::mutex PageFault_Mutex;
|
||||||
|
|
||||||
void pxInstallSignalHandler()
|
void pxInstallSignalHandler()
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include "common/Vulkan/Builders.h"
|
#include "common/Vulkan/Builders.h"
|
||||||
#include "common/Vulkan/Util.h"
|
#include "common/Vulkan/Util.h"
|
||||||
#include "common/Assertions.h"
|
#include "common/Assertions.h"
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
namespace Vulkan
|
namespace Vulkan
|
||||||
{
|
{
|
||||||
|
@ -881,4 +882,4 @@ namespace Vulkan
|
||||||
m_ci.offset = offset;
|
m_ci.offset = offset;
|
||||||
m_ci.range = size;
|
m_ci.range = size;
|
||||||
}
|
}
|
||||||
} // namespace Vulkan
|
} // namespace Vulkan
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
#include "common/RedtapeWindows.h"
|
#include "common/RedtapeWindows.h"
|
||||||
#include "common/PageFaultSource.h"
|
#include "common/PageFaultSource.h"
|
||||||
|
#include "common/Console.h"
|
||||||
|
|
||||||
static long DoSysPageFaultExceptionFilter(EXCEPTION_POINTERS* eps)
|
static long DoSysPageFaultExceptionFilter(EXCEPTION_POINTERS* eps)
|
||||||
{
|
{
|
||||||
|
@ -26,7 +27,7 @@ static long DoSysPageFaultExceptionFilter(EXCEPTION_POINTERS* eps)
|
||||||
// Note: This exception can be accessed by the EE or MTVU thread
|
// Note: This exception can be accessed by the EE or MTVU thread
|
||||||
// Source_PageFault is a global variable with its own state information
|
// Source_PageFault is a global variable with its own state information
|
||||||
// so for now we lock this exception code unless someone can fix this better...
|
// so for now we lock this exception code unless someone can fix this better...
|
||||||
Threading::ScopedLock lock(PageFault_Mutex);
|
std::unique_lock lock(PageFault_Mutex);
|
||||||
Source_PageFault->Dispatch(PageFaultInfo((uptr)eps->ExceptionRecord->ExceptionInformation[1]));
|
Source_PageFault->Dispatch(PageFaultInfo((uptr)eps->ExceptionRecord->ExceptionInformation[1]));
|
||||||
return Source_PageFault->WasHandled() ? EXCEPTION_CONTINUE_EXECUTION : EXCEPTION_CONTINUE_SEARCH;
|
return Source_PageFault->WasHandled() ? EXCEPTION_CONTINUE_EXECUTION : EXCEPTION_CONTINUE_SEARCH;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "GS/GS.h"
|
#include "GS/GS.h"
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <mutex>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
extern double GetVerticalFrequency();
|
extern double GetVerticalFrequency();
|
||||||
|
@ -333,8 +334,8 @@ public:
|
||||||
std::atomic<int> m_QueuedFrameCount;
|
std::atomic<int> m_QueuedFrameCount;
|
||||||
std::atomic<bool> m_VsyncSignalListener;
|
std::atomic<bool> m_VsyncSignalListener;
|
||||||
|
|
||||||
Threading::Mutex m_mtx_RingBufferBusy2; // Gets released on semaXGkick waiting...
|
std::mutex m_mtx_RingBufferBusy2; // Gets released on semaXGkick waiting...
|
||||||
Threading::Mutex m_mtx_WaitGS;
|
std::mutex m_mtx_WaitGS;
|
||||||
Threading::WorkSema m_sem_event;
|
Threading::WorkSema m_sem_event;
|
||||||
Threading::KernelSemaphore m_sem_OnRingReset;
|
Threading::KernelSemaphore m_sem_OnRingReset;
|
||||||
Threading::KernelSemaphore m_sem_Vsync;
|
Threading::KernelSemaphore m_sem_Vsync;
|
||||||
|
@ -355,7 +356,7 @@ public:
|
||||||
uint m_packet_writepos; // index of the data location in the ringbuffer.
|
uint m_packet_writepos; // index of the data location in the ringbuffer.
|
||||||
|
|
||||||
#ifdef RINGBUF_DEBUG_STACK
|
#ifdef RINGBUF_DEBUG_STACK
|
||||||
Threading::Mutex m_lock_Stack;
|
std::mutex m_lock_Stack;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::thread m_thread;
|
std::thread m_thread;
|
||||||
|
|
|
@ -276,7 +276,7 @@ void SysMtgsThread::MainLoop()
|
||||||
PacketTagType prevCmd;
|
PacketTagType prevCmd;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ScopedLock mtvu_lock(m_mtx_RingBufferBusy2);
|
std::unique_lock mtvu_lock(m_mtx_RingBufferBusy2);
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
@ -285,14 +285,13 @@ void SysMtgsThread::MainLoop()
|
||||||
// is very optimized (only 1 instruction test in most cases), so no point in trying
|
// is very optimized (only 1 instruction test in most cases), so no point in trying
|
||||||
// to avoid it.
|
// to avoid it.
|
||||||
|
|
||||||
m_mtx_RingBufferBusy2.Release();
|
mtvu_lock.unlock();
|
||||||
|
|
||||||
m_sem_event.WaitForWork();
|
m_sem_event.WaitForWork();
|
||||||
|
mtvu_lock.lock();
|
||||||
|
|
||||||
if (!m_open_flag.load(std::memory_order_acquire))
|
if (!m_open_flag.load(std::memory_order_acquire))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
m_mtx_RingBufferBusy2.Acquire();
|
|
||||||
|
|
||||||
// note: m_ReadPos is intentionally not volatile, because it should only
|
// note: m_ReadPos is intentionally not volatile, because it should only
|
||||||
// ever be modified by this thread.
|
// ever be modified by this thread.
|
||||||
while (m_ReadPos.load(std::memory_order_relaxed) != m_WritePos.load(std::memory_order_acquire))
|
while (m_ReadPos.load(std::memory_order_relaxed) != m_WritePos.load(std::memory_order_acquire))
|
||||||
|
@ -413,10 +412,10 @@ void SysMtgsThread::MainLoop()
|
||||||
MTVU_LOG("MTGS - Waiting on semaXGkick!");
|
MTVU_LOG("MTGS - Waiting on semaXGkick!");
|
||||||
if (!vu1Thread.semaXGkick.TryWait())
|
if (!vu1Thread.semaXGkick.TryWait())
|
||||||
{
|
{
|
||||||
mtvu_lock.Release();
|
mtvu_lock.unlock();
|
||||||
// Wait for MTVU to complete vu1 program
|
// Wait for MTVU to complete vu1 program
|
||||||
vu1Thread.semaXGkick.Wait();
|
vu1Thread.semaXGkick.Wait();
|
||||||
mtvu_lock.Acquire();
|
mtvu_lock.lock();
|
||||||
}
|
}
|
||||||
Gif_Path& path = gifUnit.gifPath[GIF_PATH_1];
|
Gif_Path& path = gifUnit.gifPath[GIF_PATH_1];
|
||||||
GS_Packet gsPack = path.GetGSPacketMTVU(); // Get vu1 program's xgkick packet(s)
|
GS_Packet gsPack = path.GetGSPacketMTVU(); // Get vu1 program's xgkick packet(s)
|
||||||
|
@ -605,7 +604,9 @@ void SysMtgsThread::WaitGS(bool syncRegs, bool weakWait, bool isMTVU)
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
m_mtx_RingBufferBusy2.Wait();
|
// m_mtx_RingBufferBusy2.Wait();
|
||||||
|
m_mtx_RingBufferBusy2.lock();
|
||||||
|
m_mtx_RingBufferBusy2.unlock();
|
||||||
if (path.GetPendingGSPackets() != startP1Packs)
|
if (path.GetPendingGSPackets() != startP1Packs)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -619,7 +620,7 @@ void SysMtgsThread::WaitGS(bool syncRegs, bool weakWait, bool isMTVU)
|
||||||
|
|
||||||
if (syncRegs)
|
if (syncRegs)
|
||||||
{
|
{
|
||||||
ScopedLock lock(m_mtx_WaitGS);
|
std::unique_lock lock(m_mtx_WaitGS);
|
||||||
// Completely synchronize GS and MTGS register states.
|
// Completely synchronize GS and MTGS register states.
|
||||||
memcpy(RingBuffer.Regs, PS2MEM_GS, sizeof(RingBuffer.Regs));
|
memcpy(RingBuffer.Regs, PS2MEM_GS, sizeof(RingBuffer.Regs));
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
#include "common/StringUtil.h"
|
#include "common/StringUtil.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
static WavOutFile* _new_WavOutFile(const char* destfile)
|
static WavOutFile* _new_WavOutFile(const char* destfile)
|
||||||
{
|
{
|
||||||
return new WavOutFile(destfile, 48000, 16, 2);
|
return new WavOutFile(destfile, 48000, 16, 2);
|
||||||
|
@ -109,13 +111,13 @@ using namespace Threading;
|
||||||
bool WavRecordEnabled = false;
|
bool WavRecordEnabled = false;
|
||||||
|
|
||||||
static WavOutFile* m_wavrecord = nullptr;
|
static WavOutFile* m_wavrecord = nullptr;
|
||||||
static Mutex WavRecordMutex;
|
static std::mutex WavRecordMutex;
|
||||||
|
|
||||||
bool RecordStart(const std::string* filename)
|
bool RecordStart(const std::string* filename)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ScopedLock lock(WavRecordMutex);
|
std::unique_lock lock(WavRecordMutex);
|
||||||
safe_delete(m_wavrecord);
|
safe_delete(m_wavrecord);
|
||||||
if (filename)
|
if (filename)
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -142,13 +144,13 @@ bool RecordStart(const std::string* filename)
|
||||||
void RecordStop()
|
void RecordStop()
|
||||||
{
|
{
|
||||||
WavRecordEnabled = false;
|
WavRecordEnabled = false;
|
||||||
ScopedLock lock(WavRecordMutex);
|
std::unique_lock lock(WavRecordMutex);
|
||||||
safe_delete(m_wavrecord);
|
safe_delete(m_wavrecord);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RecordWrite(const StereoOut16& sample)
|
void RecordWrite(const StereoOut16& sample)
|
||||||
{
|
{
|
||||||
ScopedLock lock(WavRecordMutex);
|
std::unique_lock lock(WavRecordMutex);
|
||||||
if (m_wavrecord == nullptr)
|
if (m_wavrecord == nullptr)
|
||||||
return;
|
return;
|
||||||
m_wavrecord->write((s16*)&sample, 2);
|
m_wavrecord->write((s16*)&sample, 2);
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
|
|
||||||
using namespace Threading;
|
using namespace Threading;
|
||||||
|
|
||||||
MutexRecursive mtx_SPU2Status;
|
std::recursive_mutex mtx_SPU2Status;
|
||||||
|
|
||||||
int SampleRate = 48000;
|
int SampleRate = 48000;
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ uptr gsWindowHandle = 0;
|
||||||
|
|
||||||
s32 SPU2open()
|
s32 SPU2open()
|
||||||
{
|
{
|
||||||
ScopedLock lock(mtx_SPU2Status);
|
std::unique_lock lock(mtx_SPU2Status);
|
||||||
if (IsOpened)
|
if (IsOpened)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -307,7 +307,7 @@ s32 SPU2open()
|
||||||
|
|
||||||
void SPU2close()
|
void SPU2close()
|
||||||
{
|
{
|
||||||
ScopedLock lock(mtx_SPU2Status);
|
std::unique_lock lock(mtx_SPU2Status);
|
||||||
if (!IsOpened)
|
if (!IsOpened)
|
||||||
return;
|
return;
|
||||||
IsOpened = false;
|
IsOpened = false;
|
||||||
|
|
|
@ -15,11 +15,11 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "common/Threading.h"
|
|
||||||
#include "SaveState.h"
|
#include "SaveState.h"
|
||||||
#include "IopCounters.h"
|
#include "IopCounters.h"
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
extern Threading::MutexRecursive mtx_SPU2Status;
|
extern std::recursive_mutex mtx_SPU2Status;
|
||||||
|
|
||||||
enum class PS2Modes
|
enum class PS2Modes
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue