mirror of
https://github.com/edubart/otclient.git
synced 2025-12-18 14:47:11 +01:00
Use boost::thread instead of std::thread
This commit is contained in:
@@ -38,7 +38,7 @@ void AsyncDispatcher::terminate()
|
||||
void AsyncDispatcher::spawn_thread()
|
||||
{
|
||||
m_running = true;
|
||||
m_threads.push_back(std::thread(std::bind(&AsyncDispatcher::exec_loop, this)));
|
||||
m_threads.push_back(stdext::thread(std::bind(&AsyncDispatcher::exec_loop, this)));
|
||||
}
|
||||
|
||||
void AsyncDispatcher::stop()
|
||||
@@ -47,13 +47,13 @@ void AsyncDispatcher::stop()
|
||||
m_running = false;
|
||||
m_condition.notify_all();
|
||||
m_mutex.unlock();
|
||||
for(std::thread& thread : m_threads)
|
||||
for(stdext::thread& thread : m_threads)
|
||||
thread.join();
|
||||
m_threads.clear();
|
||||
};
|
||||
|
||||
void AsyncDispatcher::exec_loop() {
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
stdext::unique_lock<stdext::mutex> lock(m_mutex);
|
||||
while(true) {
|
||||
while(m_tasks.size() == 0 && m_running)
|
||||
m_condition.wait(lock);
|
||||
|
||||
@@ -35,9 +35,9 @@ public:
|
||||
void stop();
|
||||
|
||||
template<class F>
|
||||
std::future<typename std::result_of<F()>::type> schedule(const F& task) {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
auto prom = std::make_shared<std::promise<typename std::result_of<F()>::type>>();
|
||||
stdext::future<typename std::result_of<F()>::type> schedule(const F& task) {
|
||||
stdext::lock_guard<stdext::mutex> lock(m_mutex);
|
||||
auto prom = std::make_shared<stdext::promise<typename std::result_of<F()>::type>>();
|
||||
m_tasks.push_back([=]() { prom->set_value(task()); });
|
||||
m_condition.notify_all();
|
||||
return prom->get_future();
|
||||
@@ -48,9 +48,9 @@ protected:
|
||||
|
||||
private:
|
||||
std::list<std::function<void()>> m_tasks;
|
||||
std::mutex m_mutex;
|
||||
std::list<std::thread> m_threads;
|
||||
std::condition_variable m_condition;
|
||||
stdext::mutex m_mutex;
|
||||
std::list<stdext::thread> m_threads;
|
||||
stdext::condition_variable m_condition;
|
||||
stdext::boolean<false> m_running;
|
||||
};
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ Logger g_logger;
|
||||
|
||||
void Logger::log(Fw::LogLevel level, const std::string& message)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(m_mutex);
|
||||
stdext::lock_guard<stdext::recursive_mutex> lock(m_mutex);
|
||||
|
||||
#ifdef NDEBUG
|
||||
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)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(m_mutex);
|
||||
stdext::lock_guard<stdext::recursive_mutex> lock(m_mutex);
|
||||
|
||||
prettyFunction = prettyFunction.substr(0, prettyFunction.find_first_of('('));
|
||||
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()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(m_mutex);
|
||||
stdext::lock_guard<stdext::recursive_mutex> lock(m_mutex);
|
||||
|
||||
if(m_onLog) {
|
||||
auto backup = m_logMessages;
|
||||
@@ -130,7 +130,7 @@ void Logger::fireOldMessages()
|
||||
|
||||
void Logger::setLogFile(const std::string& file)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(m_mutex);
|
||||
stdext::lock_guard<stdext::recursive_mutex> lock(m_mutex);
|
||||
|
||||
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()) {
|
||||
|
||||
@@ -62,7 +62,7 @@ private:
|
||||
std::list<LogMessage> m_logMessages;
|
||||
OnLogCallback m_onLog;
|
||||
std::ofstream m_outFile;
|
||||
std::recursive_mutex m_mutex;
|
||||
stdext::recursive_mutex m_mutex;
|
||||
};
|
||||
|
||||
extern Logger g_logger;
|
||||
|
||||
Reference in New Issue
Block a user