From 347e69007b9b612d420e676c2fa0d7faf6a347d8 Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Fri, 19 Sep 2014 09:47:35 +0700 Subject: [PATCH] Add GLCriticalSection class. Make PluginAPI descendant of GLCriticalSection. --- GLCriticalSection.h | 37 +++++++++++++++++++++++++++ GLideN64.vcxproj | 1 + GLideN64.vcxproj.filters | 3 +++ PluginAPI.h | 4 ++- common/CommonAPIImpl_common.cpp | 2 ++ mupenplus/CommonAPIImpl_mupenplus.cpp | 1 + windows/CommonAPIImpl_windows.cpp | 1 + 7 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 GLCriticalSection.h diff --git a/GLCriticalSection.h b/GLCriticalSection.h new file mode 100644 index 00000000..b994c5ee --- /dev/null +++ b/GLCriticalSection.h @@ -0,0 +1,37 @@ +#ifndef GLCRITICALSECTION_H +#define GLCRITICALSECTION_H + +#include // std::mutex + +class GLCriticalSection +{ +public: + void lock() + { + m_mtx.lock(); + m_locked = true; + } + + void unlock() + { + m_locked = false; + m_mtx.unlock(); + } + + bool isLocked() const {return m_locked;} + +protected: + class Lock { + public: + Lock(GLCriticalSection * _pCS) : m_pCS(_pCS) {m_pCS->lock();} + ~Lock() {m_pCS->unlock();} + private: + GLCriticalSection * m_pCS; + }; + +private: + std::mutex m_mtx; + bool m_locked; +}; + +#endif // GLCRITICALSECTION_H diff --git a/GLideN64.vcxproj b/GLideN64.vcxproj index 7aead5f2..c7adc3ec 100644 --- a/GLideN64.vcxproj +++ b/GLideN64.vcxproj @@ -345,6 +345,7 @@ + diff --git a/GLideN64.vcxproj.filters b/GLideN64.vcxproj.filters index c1a4df66..e4b4b5cd 100644 --- a/GLideN64.vcxproj.filters +++ b/GLideN64.vcxproj.filters @@ -305,6 +305,9 @@ Header Files + + Header Files + diff --git a/PluginAPI.h b/PluginAPI.h index 0f9a3a9b..b672fef8 100644 --- a/PluginAPI.h +++ b/PluginAPI.h @@ -7,7 +7,9 @@ #include "ZilmarGFX_1_3.h" #endif -class PluginAPI +#include "GLCriticalSection.h" + +class PluginAPI : public GLCriticalSection { public: // Common diff --git a/common/CommonAPIImpl_common.cpp b/common/CommonAPIImpl_common.cpp index 221f4a46..a0218e89 100644 --- a/common/CommonAPIImpl_common.cpp +++ b/common/CommonAPIImpl_common.cpp @@ -15,6 +15,7 @@ void PluginAPI::ProcessDList() { + Lock lock(this); RSP_ProcessDList(); } @@ -45,6 +46,7 @@ void PluginAPI::ShowCFB() void PluginAPI::UpdateScreen() { + Lock lock(this); VI_UpdateScreen(); } diff --git a/mupenplus/CommonAPIImpl_mupenplus.cpp b/mupenplus/CommonAPIImpl_mupenplus.cpp index 8bd71e1a..cb081cb8 100644 --- a/mupenplus/CommonAPIImpl_mupenplus.cpp +++ b/mupenplus/CommonAPIImpl_mupenplus.cpp @@ -4,6 +4,7 @@ int PluginAPI::InitiateGFX(const GFX_INFO & _gfxInfo) { + Lock lock(this); _initiateGFX(_gfxInfo); Config_LoadConfig(); diff --git a/windows/CommonAPIImpl_windows.cpp b/windows/CommonAPIImpl_windows.cpp index 2872d294..40489b6c 100644 --- a/windows/CommonAPIImpl_windows.cpp +++ b/windows/CommonAPIImpl_windows.cpp @@ -14,6 +14,7 @@ BOOL CALLBACK FindToolBarProc( HWND hWnd, LPARAM lParam ) int PluginAPI::InitiateGFX(const GFX_INFO & _gfxInfo) { + Lock lock(this); _initiateGFX(_gfxInfo); hWnd = _gfxInfo.hWnd;