Fix ubuntu compile errors
This commit is contained in:
parent
1dd558d57e
commit
44bf4dcb6e
|
@ -196,7 +196,6 @@ message(STATUS "Build revision: ${BUILD_REVISION}")
|
||||||
add_definitions(-D"BUILD_REVISION=\\\"${BUILD_REVISION}\\\"")
|
add_definitions(-D"BUILD_REVISION=\\\"${BUILD_REVISION}\\\"")
|
||||||
|
|
||||||
# find boost
|
# find boost
|
||||||
set(framework_DEFINITIONS ${framework_DEFINITIONS} -DBOOST_THREAD_PROVIDES_FUTURE) # enable boost::future
|
|
||||||
set(REQUIRED_BOOST_COMPONENTS system thread chrono)
|
set(REQUIRED_BOOST_COMPONENTS system thread chrono)
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
set(Boost_THREADAPI win32)
|
set(Boost_THREADAPI win32)
|
||||||
|
|
|
@ -35,9 +35,9 @@ public:
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
template<class F>
|
template<class F>
|
||||||
std::future<typename std::result_of<F()>::type> schedule(const F& task) {
|
boost::unique_future<typename std::result_of<F()>::type> schedule(const F& task) {
|
||||||
std::lock_guard<std::mutex> lock(m_mutex);
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
auto prom = std::make_shared<std::promise<typename std::result_of<F()>::type>>();
|
auto prom = std::make_shared<boost::promise<typename std::result_of<F()>::type>>();
|
||||||
m_tasks.push_back([=]() { prom->set_value(task()); });
|
m_tasks.push_back([=]() { prom->set_value(task()); });
|
||||||
m_condition.notify_all();
|
m_condition.notify_all();
|
||||||
return prom->get_future();
|
return prom->get_future();
|
||||||
|
@ -48,8 +48,8 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::list<std::function<void()>> m_tasks;
|
std::list<std::function<void()>> m_tasks;
|
||||||
std::mutex m_mutex;
|
|
||||||
std::list<std::thread> m_threads;
|
std::list<std::thread> m_threads;
|
||||||
|
std::mutex m_mutex;
|
||||||
std::condition_variable m_condition;
|
std::condition_variable m_condition;
|
||||||
stdext::boolean<false> m_running;
|
stdext::boolean<false> m_running;
|
||||||
};
|
};
|
||||||
|
|
|
@ -96,9 +96,9 @@ void SoundManager::poll()
|
||||||
|
|
||||||
for(auto it = m_streamFiles.begin(); it != m_streamFiles.end();) {
|
for(auto it = m_streamFiles.begin(); it != m_streamFiles.end();) {
|
||||||
StreamSoundSourcePtr source = it->first;
|
StreamSoundSourcePtr source = it->first;
|
||||||
std::future<SoundFilePtr>& future = it->second;
|
auto& future = it->second;
|
||||||
|
|
||||||
if(std::is_ready(future)) {
|
if(future.is_ready()) {
|
||||||
SoundFilePtr sound = future.get();
|
SoundFilePtr sound = future.get();
|
||||||
if(sound)
|
if(sound)
|
||||||
source->setSoundFile(sound);
|
source->setSoundFile(sound);
|
||||||
|
@ -264,7 +264,7 @@ SoundSourcePtr SoundManager::createSoundSource(const std::string& filename)
|
||||||
source = combinedSource;
|
source = combinedSource;
|
||||||
#else
|
#else
|
||||||
StreamSoundSourcePtr streamSource(new StreamSoundSource);
|
StreamSoundSourcePtr streamSource(new StreamSoundSource);
|
||||||
m_streamFiles[streamSource] = m_loadJobs [=]() -> SoundFilePtr {
|
m_streamFiles[streamSource] = g_asyncDispatcher.schedule([=]() -> SoundFilePtr {
|
||||||
try {
|
try {
|
||||||
return SoundFile::loadSoundFile(filename);
|
return SoundFile::loadSoundFile(filename);
|
||||||
} catch(std::exception& e) {
|
} catch(std::exception& e) {
|
||||||
|
|
|
@ -57,7 +57,7 @@ private:
|
||||||
ALCdevice *m_device;
|
ALCdevice *m_device;
|
||||||
ALCcontext *m_context;
|
ALCcontext *m_context;
|
||||||
|
|
||||||
std::map<StreamSoundSourcePtr, std::future<SoundFilePtr>> m_streamFiles;
|
std::map<StreamSoundSourcePtr, boost::unique_future<SoundFilePtr>> m_streamFiles;
|
||||||
std::unordered_map<std::string, SoundBufferPtr> m_buffers;
|
std::unordered_map<std::string, SoundBufferPtr> m_buffers;
|
||||||
std::vector<SoundSourcePtr> m_sources;
|
std::vector<SoundSourcePtr> m_sources;
|
||||||
stdext::boolean<true> m_audioEnabled;
|
stdext::boolean<true> m_audioEnabled;
|
||||||
|
|
|
@ -23,48 +23,33 @@
|
||||||
#ifndef THREAD_H
|
#ifndef THREAD_H
|
||||||
#define THREAD_H
|
#define THREAD_H
|
||||||
|
|
||||||
|
#include <boost/thread/future.hpp>
|
||||||
|
|
||||||
// hack to enable std::thread on mingw32 4.6
|
// hack to enable std::thread on mingw32 4.6
|
||||||
#if !defined(_GLIBCXX_HAS_GTHREADS) && defined(__GNUG__)
|
#if !defined(_GLIBCXX_HAS_GTHREADS) && defined(__GNUG__)
|
||||||
|
|
||||||
#include <boost/thread/thread.hpp>
|
#include <boost/thread/thread.hpp>
|
||||||
#include <boost/thread/mutex.hpp>
|
#include <boost/thread/mutex.hpp>
|
||||||
#include <boost/thread/recursive_mutex.hpp>
|
#include <boost/thread/recursive_mutex.hpp>
|
||||||
#include <boost/thread/locks.hpp>
|
#include <boost/thread/locks.hpp>
|
||||||
#include <boost/thread/future.hpp>
|
|
||||||
#include <boost/thread/condition_variable.hpp>
|
#include <boost/thread/condition_variable.hpp>
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
using boost::thread;
|
using boost::thread;
|
||||||
using boost::future;
|
|
||||||
using boost::future_status;
|
|
||||||
using boost::promise;
|
|
||||||
|
|
||||||
using boost::mutex;
|
using boost::mutex;
|
||||||
using boost::timed_mutex;
|
|
||||||
using boost::recursive_mutex;
|
using boost::recursive_mutex;
|
||||||
using boost::recursive_timed_mutex;
|
|
||||||
|
|
||||||
using boost::lock_guard;
|
using boost::lock_guard;
|
||||||
using boost::unique_lock;
|
using boost::unique_lock;
|
||||||
|
|
||||||
using boost::condition_variable;
|
using boost::condition_variable;
|
||||||
using boost::condition_variable_any;
|
|
||||||
|
|
||||||
template<typename R>
|
|
||||||
bool is_ready(std::future<R>& f)
|
|
||||||
{ return f.wait_for(boost::chrono::seconds(0)) == future_status::ready; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <future>
|
|
||||||
|
|
||||||
namespace std {
|
|
||||||
template<typename R>
|
|
||||||
bool is_ready(std::future<R>& f)
|
|
||||||
{ return f.wait_for(chrono::seconds(0)) == future_status::ready; }
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue