From eea4118eedf6163c4a1cb364eb379d04e0cc3e3d Mon Sep 17 00:00:00 2001 From: Daniel Evans Date: Tue, 5 Aug 2014 13:41:44 +0100 Subject: [PATCH] Change threading in naieve attempt at fixing crash --- CMakeLists.txt | 6 ++++-- rwengine/include/audio/MADStream.hpp | 2 +- rwengine/src/WorkContext.cpp | 19 +++++++++++-------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 40c1e9fa..a4299a01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,10 +11,12 @@ SET(BUILD_SCRIPT_TOOL TRUE CACHE BOOL "Build script decompiler tool") SET(BUILD_OLD_TOOLS FALSE CACHE BOOL "Build old datadump and analyzer tools") +SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -pthread") + IF(CMAKE_BUILD_TYPE MATCHES Debug) - set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++11 -Wall -Wextra" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wextra" ) ELSE() - set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -std=c++11 -Wall" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3" ) ENDIF() # Make GLM use radians diff --git a/rwengine/include/audio/MADStream.hpp b/rwengine/include/audio/MADStream.hpp index 5abd67f6..18364d5a 100644 --- a/rwengine/include/audio/MADStream.hpp +++ b/rwengine/include/audio/MADStream.hpp @@ -121,8 +121,8 @@ public: if( mFdm ) { munmap( mFdm, mStat.st_size ); + mad_decoder_finish(&mDecoder); } - mad_decoder_finish(&mDecoder); } bool open(const std::string& loc) diff --git a/rwengine/src/WorkContext.cpp b/rwengine/src/WorkContext.cpp index 4d9445ab..a5ad1e4e 100644 --- a/rwengine/src/WorkContext.cpp +++ b/rwengine/src/WorkContext.cpp @@ -12,18 +12,21 @@ void LoadWorker::start() void WorkContext::workNext() { WorkJob* j = nullptr; - { - std::lock_guard guard( _inMutex ); - if( _workQueue.empty() ) return; - j = _workQueue.front(); _workQueue.pop(); + + _inMutex.lock(); + if( ! _workQueue.empty() ) { + j = _workQueue.front(); + _workQueue.pop(); } + _inMutex.unlock(); + + if( j == nullptr ) return; j->work(); - { - std::lock_guard guard( _outMutex ); - _completeQueue.push( j ); - } + _outMutex.lock(); + _completeQueue.push(j); + _outMutex.unlock(); } void WorkContext::update()