From 77c00bc77f6ca577c205ad28693fe4acd26d3150 Mon Sep 17 00:00:00 2001 From: Dale Stammen Date: Mon, 27 Oct 2014 08:32:19 -0700 Subject: [PATCH] removed use of std::mutex. Now using lock-free concurrent_queue --- cocos/platform/winrt/CCGLViewImpl-winrt.cpp | 11 +++-------- cocos/platform/winrt/CCGLViewImpl-winrt.h | 7 ++++--- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/cocos/platform/winrt/CCGLViewImpl-winrt.cpp b/cocos/platform/winrt/CCGLViewImpl-winrt.cpp index 4526c07091..2447517136 100644 --- a/cocos/platform/winrt/CCGLViewImpl-winrt.cpp +++ b/cocos/platform/winrt/CCGLViewImpl-winrt.cpp @@ -33,6 +33,7 @@ THE SOFTWARE. #include "deprecated/CCNotificationCenter.h" using namespace Platform; +using namespace Concurrency; using namespace Windows::Foundation; using namespace Windows::Foundation::Collections; using namespace Windows::Graphics::Display; @@ -454,33 +455,27 @@ void GLViewImpl::setScissorInPoints(float x , float y , float w , float h) void GLViewImpl::QueueBackKeyPress() { - std::lock_guard guard(mMutex); std::shared_ptr e(new BackButtonEvent()); mInputEvents.push(e); } void GLViewImpl::QueuePointerEvent(PointerEventType type, PointerEventArgs^ args) { - std::lock_guard guard(mMutex); std::shared_ptr e(new PointerEvent(type, args)); mInputEvents.push(e); } void GLViewImpl::QueueEvent(std::shared_ptr& event) { - std::lock_guard guard(mMutex); mInputEvents.push(event); } void GLViewImpl::ProcessEvents() { - std::lock_guard guard(mMutex); - - while (!mInputEvents.empty()) + std::shared_ptr e; + while (mInputEvents.try_pop(e)) { - InputEvent* e = mInputEvents.front().get(); e->execute(); - mInputEvents.pop(); } } diff --git a/cocos/platform/winrt/CCGLViewImpl-winrt.h b/cocos/platform/winrt/CCGLViewImpl-winrt.h index 33eac1cfbe..6cca0524ff 100644 --- a/cocos/platform/winrt/CCGLViewImpl-winrt.h +++ b/cocos/platform/winrt/CCGLViewImpl-winrt.h @@ -33,9 +33,9 @@ THE SOFTWARE. #include +#include #include #include -#include #include #include @@ -156,8 +156,9 @@ private: Cocos2dMessageBoxDelegate^ m_messageBoxDelegate; Cocos2dEditBoxDelegate^ m_editBoxDelegate; - std::queue> mInputEvents; - std::mutex mMutex; + Concurrency::concurrent_queue> mInputEvents; + //std::queue> mInputEvents; + //Concurrency::critical_section m_criticalSection; Platform::Agile m_dispatcher; Platform::Agile m_panel;