Switch to C++11 threads, mutexes and lock_guards. Switching to C++11 condition_variables requires some more thought.

This commit is contained in:
Erik Hofman
2020-01-22 13:44:47 +01:00
parent 867cf6b60a
commit aab88b411e
27 changed files with 160 additions and 351 deletions
+5 -5
View File
@@ -31,7 +31,7 @@
#elif defined(GCC_ATOMIC_BUILTINS_FOUND)
#elif defined(__GNUC__) && defined(__i386__)
#elif defined(SGATOMIC_USE_MUTEX)
# include <simgear/threads/SGGuard.hxx>
# include <mutex>
#else
# error
#endif
@@ -52,7 +52,7 @@ SGAtomic::operator++()
: "memory");
return result + 1;
#else
SGGuard<SGMutex> lock(mMutex);
std::lock_guard<std::mutex> lock(mMutex);
return ++mValue;
#endif
}
@@ -73,7 +73,7 @@ SGAtomic::operator--()
: "memory");
return result - 1;
#else
SGGuard<SGMutex> lock(mMutex);
std::lock_guard<std::mutex> lock(mMutex);
return --mValue;
#endif
}
@@ -89,7 +89,7 @@ SGAtomic::operator unsigned() const
__asm__ __volatile__("": : : "memory");
return mValue;
#else
SGGuard<SGMutex> lock(mMutex);
std::lock_guard<std::mutex> lock(mMutex);
return mValue;
#endif
}
@@ -111,7 +111,7 @@ SGAtomic::compareAndExchange(unsigned oldValue, unsigned newValue)
: "memory");
return before == oldValue;
#else
SGGuard<SGMutex> lock(mMutex);
std::lock_guard<std::mutex> lock(mMutex);
if (mValue != oldValue)
return false;
mValue = newValue;
+1 -1
View File
@@ -111,7 +111,7 @@ private:
SGAtomic& operator=(const SGAtomic&);
#if defined(SGATOMIC_USE_MUTEX)
mutable SGMutex mMutex;
mutable std::mutex mMutex;
#endif
unsigned mValue;
};
+1 -2
View File
@@ -1,6 +1,5 @@
#include "StringTable.hxx"
#include <simgear/threads/SGGuard.hxx>
namespace simgear
{
@@ -8,7 +7,7 @@ using namespace std;
const string* StringTable::insert(const string& str)
{
SGGuard<SGMutex> lock(_mutex);
std::lock_guard<std::mutex> lock(_mutex);
StringContainer::iterator it = _strings.insert(str).first;
return &*it;
}
+2 -2
View File
@@ -2,8 +2,8 @@
#define SIMGEAR_STRINGTABLE_HXX 1
#include <string>
#include <mutex>
#include <simgear/threads/SGThread.hxx>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/identity.hpp>
@@ -21,7 +21,7 @@ class StringTable
{
const std::string* insert(const std::string& str);
private:
SGMutex _mutex;
std::mutex _mutex;
StringContainer _strings;
};
}
+4 -4
View File
@@ -8,6 +8,7 @@
#include <memory>
#include <cassert>
#include <mutex>
#include <simgear/props/props_io.hxx>
@@ -15,7 +16,6 @@
#include <simgear/structure/exception.hxx>
#include <simgear/threads/SGThread.hxx>
#include <simgear/threads/SGGuard.hxx>
#include <simgear/debug/logstream.hxx>
struct Invocation
@@ -32,7 +32,7 @@ public:
using InvocactionVec = std::vector<Invocation>;
InvocactionVec _queue;
SGMutex _mutex;
std::mutex _mutex;
using command_map = std::map<std::string,Command*> ;
command_map _commands;
@@ -179,7 +179,7 @@ void SGCommandMgr::queuedExecute(const std::string &name, const SGPropertyNode*
{
Invocation invoke = {name, new SGPropertyNode};
copyProperties(arg, invoke.args);
SGGuard<SGMutex> g(d->_mutex);
std::lock_guard<std::mutex> g(d->_mutex);
d->_queue.push_back(invoke);
}
@@ -192,7 +192,7 @@ void SGCommandMgr::executedQueuedCommands()
// locked swap with the shared queue
Private::InvocactionVec q;
{
SGGuard<SGMutex> g(d->_mutex);
std::lock_guard<std::mutex> g(d->_mutex);
d->_queue.swap(q);
}