Revert "Use boost::thread instead of std::thread"

This reverts commit 71b5c5f2e4.
This commit is contained in:
Eduardo Bart 2013-03-05 01:47:23 -03:00
parent 8c016b143a
commit 1dd558d57e
8 changed files with 23 additions and 49 deletions

View File

@ -252,7 +252,6 @@ function getItemPrice(item, single)
if not single then if not single then
amount = quantityScroll:getValue() amount = quantityScroll:getValue()
end end
if getCurrentTradeType() == BUY then if getCurrentTradeType() == BUY then
if buyWithBackpack:isChecked() then if buyWithBackpack:isChecked() then
if item.ptr:isStackable() then if item.ptr:isStackable() then
@ -392,7 +391,6 @@ function refreshPlayerGoods()
end end
function onOpenNpcTrade(items) function onOpenNpcTrade(items)
table.dump(items)
tradeItems[BUY] = {} tradeItems[BUY] = {}
tradeItems[SELL] = {} tradeItems[SELL] = {}

View File

@ -38,7 +38,7 @@ void AsyncDispatcher::terminate()
void AsyncDispatcher::spawn_thread() void AsyncDispatcher::spawn_thread()
{ {
m_running = true; m_running = true;
m_threads.push_back(stdext::thread(std::bind(&AsyncDispatcher::exec_loop, this))); m_threads.push_back(std::thread(std::bind(&AsyncDispatcher::exec_loop, this)));
} }
void AsyncDispatcher::stop() void AsyncDispatcher::stop()
@ -47,13 +47,13 @@ void AsyncDispatcher::stop()
m_running = false; m_running = false;
m_condition.notify_all(); m_condition.notify_all();
m_mutex.unlock(); m_mutex.unlock();
for(stdext::thread& thread : m_threads) for(std::thread& thread : m_threads)
thread.join(); thread.join();
m_threads.clear(); m_threads.clear();
}; };
void AsyncDispatcher::exec_loop() { void AsyncDispatcher::exec_loop() {
stdext::unique_lock<stdext::mutex> lock(m_mutex); std::unique_lock<std::mutex> lock(m_mutex);
while(true) { while(true) {
while(m_tasks.size() == 0 && m_running) while(m_tasks.size() == 0 && m_running)
m_condition.wait(lock); m_condition.wait(lock);

View File

@ -35,9 +35,9 @@ public:
void stop(); void stop();
template<class F> template<class F>
stdext::future<typename std::result_of<F()>::type> schedule(const F& task) { std::future<typename std::result_of<F()>::type> schedule(const F& task) {
stdext::lock_guard<stdext::mutex> lock(m_mutex); std::lock_guard<std::mutex> lock(m_mutex);
auto prom = std::make_shared<stdext::promise<typename std::result_of<F()>::type>>(); auto prom = std::make_shared<std::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,9 +48,9 @@ protected:
private: private:
std::list<std::function<void()>> m_tasks; std::list<std::function<void()>> m_tasks;
stdext::mutex m_mutex; std::mutex m_mutex;
std::list<stdext::thread> m_threads; std::list<std::thread> m_threads;
stdext::condition_variable m_condition; std::condition_variable m_condition;
stdext::boolean<false> m_running; stdext::boolean<false> m_running;
}; };

View File

@ -35,7 +35,7 @@ Logger g_logger;
void Logger::log(Fw::LogLevel level, const std::string& message) void Logger::log(Fw::LogLevel level, const std::string& message)
{ {
stdext::lock_guard<stdext::recursive_mutex> lock(m_mutex); std::lock_guard<std::recursive_mutex> lock(m_mutex);
#ifdef NDEBUG #ifdef NDEBUG
if(level == Fw::LogDebug) if(level == Fw::LogDebug)
@ -97,7 +97,7 @@ void Logger::log(Fw::LogLevel level, const std::string& message)
void Logger::logFunc(Fw::LogLevel level, const std::string& message, std::string prettyFunction) void Logger::logFunc(Fw::LogLevel level, const std::string& message, std::string prettyFunction)
{ {
stdext::lock_guard<stdext::recursive_mutex> lock(m_mutex); std::lock_guard<std::recursive_mutex> lock(m_mutex);
prettyFunction = prettyFunction.substr(0, prettyFunction.find_first_of('(')); prettyFunction = prettyFunction.substr(0, prettyFunction.find_first_of('('));
if(prettyFunction.find_last_of(' ') != std::string::npos) if(prettyFunction.find_last_of(' ') != std::string::npos)
@ -118,7 +118,7 @@ void Logger::logFunc(Fw::LogLevel level, const std::string& message, std::string
void Logger::fireOldMessages() void Logger::fireOldMessages()
{ {
stdext::lock_guard<stdext::recursive_mutex> lock(m_mutex); std::lock_guard<std::recursive_mutex> lock(m_mutex);
if(m_onLog) { if(m_onLog) {
auto backup = m_logMessages; auto backup = m_logMessages;
@ -130,7 +130,7 @@ void Logger::fireOldMessages()
void Logger::setLogFile(const std::string& file) void Logger::setLogFile(const std::string& file)
{ {
stdext::lock_guard<stdext::recursive_mutex> lock(m_mutex); std::lock_guard<std::recursive_mutex> lock(m_mutex);
m_outFile.open(stdext::utf8_to_latin1(file.c_str()).c_str(), std::ios::out | std::ios::app); m_outFile.open(stdext::utf8_to_latin1(file.c_str()).c_str(), std::ios::out | std::ios::app);
if(!m_outFile.is_open() || !m_outFile.good()) { if(!m_outFile.is_open() || !m_outFile.good()) {

View File

@ -62,7 +62,7 @@ private:
std::list<LogMessage> m_logMessages; std::list<LogMessage> m_logMessages;
OnLogCallback m_onLog; OnLogCallback m_onLog;
std::ofstream m_outFile; std::ofstream m_outFile;
stdext::recursive_mutex m_mutex; std::recursive_mutex m_mutex;
}; };
extern Logger g_logger; extern Logger g_logger;

View File

@ -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;
stdext::future<SoundFilePtr>& future = it->second; std::future<SoundFilePtr>& future = it->second;
if(stdext::is_ready(future)) { if(std::is_ready(future)) {
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] = g_asyncDispatcher.schedule([=]() -> SoundFilePtr { m_streamFiles[streamSource] = m_loadJobs [=]() -> SoundFilePtr {
try { try {
return SoundFile::loadSoundFile(filename); return SoundFile::loadSoundFile(filename);
} catch(std::exception& e) { } catch(std::exception& e) {

View File

@ -25,7 +25,6 @@
#include "declarations.h" #include "declarations.h"
#include "soundchannel.h" #include "soundchannel.h"
#include <framework/stdext/thread.h>
//@bindsingleton g_sounds //@bindsingleton g_sounds
class SoundManager class SoundManager
@ -58,7 +57,7 @@ private:
ALCdevice *m_device; ALCdevice *m_device;
ALCcontext *m_context; ALCcontext *m_context;
std::map<StreamSoundSourcePtr, stdext::future<SoundFilePtr>> m_streamFiles; std::map<StreamSoundSourcePtr, std::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;

View File

@ -24,15 +24,14 @@
#define THREAD_H #define THREAD_H
// hack to enable std::thread on mingw32 4.6 // hack to enable std::thread on mingw32 4.6
#if 1 #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/future.hpp>
#include <boost/thread/condition_variable.hpp> #include <boost/thread/condition_variable.hpp>
namespace stdext { namespace std {
using boost::thread; using boost::thread;
using boost::future; using boost::future;
using boost::future_status; using boost::future_status;
@ -50,43 +49,21 @@ namespace stdext {
using boost::condition_variable_any; using boost::condition_variable_any;
template<typename R> template<typename R>
bool is_ready(stdext::future<R>& f) bool is_ready(std::future<R>& f)
{ return f.wait_for(boost::chrono::seconds(0)) == future_status::ready; } { 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> #include <future>
namespace stdext { namespace std {
template<typename R> template<typename R>
bool is_ready(std::future<R>& f) bool is_ready(std::future<R>& f)
{ return f.wait_for(chrono::seconds(0)) == future_status::ready; } { return f.wait_for(chrono::seconds(0)) == future_status::ready; }
}; };
namespace stdext {
using std::thread;
using std::future;
using std::future_status;
using std::promise;
using std::mutex;
using std::timed_mutex;
using std::recursive_mutex;
using std::recursive_timed_mutex;
using std::lock_guard;
using std::unique_lock;
using std::condition_variable;
using std::condition_variable_any;
template<typename R>
bool is_ready(std::future<R>& f)
{ return f.wait_for(boost::chrono::seconds(0)) == future_status::ready; }
}
#endif #endif