diff --git a/src/framework/CMakeLists.txt b/src/framework/CMakeLists.txt index 657a457d..2d558486 100644 --- a/src/framework/CMakeLists.txt +++ b/src/framework/CMakeLists.txt @@ -196,7 +196,6 @@ message(STATUS "Build revision: ${BUILD_REVISION}") add_definitions(-D"BUILD_REVISION=\\\"${BUILD_REVISION}\\\"") # find boost -set(framework_DEFINITIONS ${framework_DEFINITIONS} -DBOOST_THREAD_PROVIDES_FUTURE) # enable boost::future set(REQUIRED_BOOST_COMPONENTS system thread chrono) if(WIN32) set(Boost_THREADAPI win32) diff --git a/src/framework/core/asyncdispatcher.h b/src/framework/core/asyncdispatcher.h index 75290550..e914cc61 100644 --- a/src/framework/core/asyncdispatcher.h +++ b/src/framework/core/asyncdispatcher.h @@ -35,9 +35,9 @@ public: void stop(); template - std::future::type> schedule(const F& task) { + boost::unique_future::type> schedule(const F& task) { std::lock_guard lock(m_mutex); - auto prom = std::make_shared::type>>(); + auto prom = std::make_shared::type>>(); m_tasks.push_back([=]() { prom->set_value(task()); }); m_condition.notify_all(); return prom->get_future(); @@ -48,8 +48,8 @@ protected: private: std::list> m_tasks; - std::mutex m_mutex; std::list m_threads; + std::mutex m_mutex; std::condition_variable m_condition; stdext::boolean m_running; }; diff --git a/src/framework/sound/soundmanager.cpp b/src/framework/sound/soundmanager.cpp index 7120bd0a..a065937a 100644 --- a/src/framework/sound/soundmanager.cpp +++ b/src/framework/sound/soundmanager.cpp @@ -96,9 +96,9 @@ void SoundManager::poll() for(auto it = m_streamFiles.begin(); it != m_streamFiles.end();) { StreamSoundSourcePtr source = it->first; - std::future& future = it->second; + auto& future = it->second; - if(std::is_ready(future)) { + if(future.is_ready()) { SoundFilePtr sound = future.get(); if(sound) source->setSoundFile(sound); @@ -264,7 +264,7 @@ SoundSourcePtr SoundManager::createSoundSource(const std::string& filename) source = combinedSource; #else StreamSoundSourcePtr streamSource(new StreamSoundSource); - m_streamFiles[streamSource] = m_loadJobs [=]() -> SoundFilePtr { + m_streamFiles[streamSource] = g_asyncDispatcher.schedule([=]() -> SoundFilePtr { try { return SoundFile::loadSoundFile(filename); } catch(std::exception& e) { diff --git a/src/framework/sound/soundmanager.h b/src/framework/sound/soundmanager.h index aa7eab78..f5de89dc 100644 --- a/src/framework/sound/soundmanager.h +++ b/src/framework/sound/soundmanager.h @@ -57,7 +57,7 @@ private: ALCdevice *m_device; ALCcontext *m_context; - std::map> m_streamFiles; + std::map> m_streamFiles; std::unordered_map m_buffers; std::vector m_sources; stdext::boolean m_audioEnabled; diff --git a/src/framework/stdext/thread.h b/src/framework/stdext/thread.h index 06737e18..ba7ae5ed 100644 --- a/src/framework/stdext/thread.h +++ b/src/framework/stdext/thread.h @@ -23,48 +23,33 @@ #ifndef THREAD_H #define THREAD_H +#include + // hack to enable std::thread on mingw32 4.6 #if !defined(_GLIBCXX_HAS_GTHREADS) && defined(__GNUG__) + #include #include #include #include -#include #include + namespace std { using boost::thread; - using boost::future; - using boost::future_status; - using boost::promise; - using boost::mutex; - using boost::timed_mutex; using boost::recursive_mutex; - using boost::recursive_timed_mutex; - using boost::lock_guard; using boost::unique_lock; - using boost::condition_variable; - using boost::condition_variable_any; - - template - bool is_ready(std::future& f) - { return f.wait_for(boost::chrono::seconds(0)) == future_status::ready; } } - + #else + #include #include #include -#include - -namespace std { - template - bool is_ready(std::future& f) - { return f.wait_for(chrono::seconds(0)) == future_status::ready; } -}; #endif #endif +