mirror of
https://github.com/overte-org/overte.git
synced 2025-04-22 14:53:24 +02:00
Add mutex protection around octal code getters
This commit is contained in:
parent
ef6d758e7f
commit
e819ab8475
5 changed files with 34 additions and 17 deletions
libraries
octree/src
shared/src
|
@ -70,7 +70,12 @@ void JurisdictionMap::copyContents(const OctalCodePtr& rootCodeIn, const std::ve
|
|||
void JurisdictionMap::copyContents(const JurisdictionMap& other) {
|
||||
_nodeType = other._nodeType;
|
||||
|
||||
init(other.getRootOctalCode(), other.getEndNodeOctalCodes());
|
||||
OctalCodePtr rootOctalCode;
|
||||
OctalCodePtrList endNodes;
|
||||
|
||||
std::tie(rootOctalCode, endNodes) = other.getRootOctalCodeAndEndNodes();
|
||||
|
||||
init(rootOctalCode, endNodes);
|
||||
}
|
||||
|
||||
JurisdictionMap::~JurisdictionMap() {
|
||||
|
@ -120,6 +125,20 @@ JurisdictionMap::JurisdictionMap(const char* rootHexCode, const char* endNodesHe
|
|||
}
|
||||
}
|
||||
|
||||
std::tuple<OctalCodePtr, OctalCodePtrList> JurisdictionMap::getRootOctalCodeAndEndNodes() const {
|
||||
std::lock_guard<std::mutex> lock(_octalCodeMutex);
|
||||
return std::tuple<OctalCodePtr, std::vector<OctalCodePtr>>(_rootOctalCode, _endNodes);
|
||||
}
|
||||
|
||||
OctalCodePtr JurisdictionMap::getRootOctalCode() const {
|
||||
std::lock_guard<std::mutex> lock(_octalCodeMutex);
|
||||
return _rootOctalCode;
|
||||
}
|
||||
|
||||
OctalCodePtrList JurisdictionMap::getEndNodeOctalCodes() const {
|
||||
std::lock_guard<std::mutex> lock(_octalCodeMutex);
|
||||
return _endNodes;
|
||||
}
|
||||
|
||||
void JurisdictionMap::init(OctalCodePtr rootOctalCode, const std::vector<OctalCodePtr>& endNodes) {
|
||||
std::lock_guard<std::mutex> lock(_octalCodeMutex);
|
||||
|
@ -160,7 +179,7 @@ bool JurisdictionMap::readFromFile(const char* filename) {
|
|||
qCDebug(octree) << "rootCode=" << rootCode;
|
||||
|
||||
std::lock_guard<std::mutex> lock(_octalCodeMutex);
|
||||
_rootOctalCode = std::shared_ptr<unsigned char>(hexStringToOctalCode(rootCode));
|
||||
_rootOctalCode = hexStringToOctalCode(rootCode);
|
||||
printOctalCode(_rootOctalCode.get());
|
||||
|
||||
settings.beginGroup("endNodes");
|
||||
|
@ -195,11 +214,10 @@ void JurisdictionMap::displayDebugDetails() const {
|
|||
|
||||
|
||||
bool JurisdictionMap::writeToFile(const char* filename) {
|
||||
std::lock_guard<std::mutex> lock(_octalCodeMutex);
|
||||
|
||||
QString settingsFile(filename);
|
||||
QSettings settings(settingsFile, QSettings::IniFormat);
|
||||
|
||||
std::lock_guard<std::mutex> lock(_octalCodeMutex);
|
||||
|
||||
QString rootNodeValue = octalCodeToHexString(_rootOctalCode.get());
|
||||
|
||||
|
|
|
@ -51,10 +51,11 @@ public:
|
|||
bool writeToFile(const char* filename);
|
||||
bool readFromFile(const char* filename);
|
||||
|
||||
OctalCodePtr getRootOctalCode() const { return _rootOctalCode; }
|
||||
std::vector<OctalCodePtr> getEndNodeOctalCodes() const { return _endNodes; }
|
||||
std::tuple<OctalCodePtr, OctalCodePtrList> JurisdictionMap::getRootOctalCodeAndEndNodes() const;
|
||||
OctalCodePtr getRootOctalCode() const;
|
||||
OctalCodePtrList getEndNodeOctalCodes() const;
|
||||
|
||||
void copyContents(const OctalCodePtr& rootCodeIn, const std::vector<OctalCodePtr>& endNodesIn);
|
||||
void copyContents(const OctalCodePtr& rootCodeIn, const OctalCodePtrList& endNodesIn);
|
||||
|
||||
int unpackFromPacket(ReceivedMessage& message);
|
||||
std::unique_ptr<NLPacket> packIntoPacket();
|
||||
|
@ -73,7 +74,7 @@ private:
|
|||
|
||||
mutable std::mutex _octalCodeMutex;
|
||||
OctalCodePtr _rootOctalCode { nullptr };
|
||||
std::vector<OctalCodePtr> _endNodes;
|
||||
OctalCodePtrList _endNodes;
|
||||
NodeType_t _nodeType;
|
||||
};
|
||||
|
||||
|
|
|
@ -154,15 +154,12 @@ void OctreeSceneStats::sceneStarted(bool isFullScene, bool isMoving, OctreeEleme
|
|||
_isFullScene = isFullScene;
|
||||
_isMoving = isMoving;
|
||||
|
||||
_jurisdictionRoot = nullptr;
|
||||
|
||||
// clear existing endNodes before copying new ones...
|
||||
_jurisdictionEndNodes.clear();
|
||||
|
||||
// setup jurisdictions
|
||||
if (jurisdictionMap) {
|
||||
_jurisdictionRoot = jurisdictionMap->getRootOctalCode();
|
||||
_jurisdictionEndNodes = jurisdictionMap->getEndNodeOctalCodes();
|
||||
std::tie(_jurisdictionRoot, _jurisdictionEndNodes) = jurisdictionMap->getRootOctalCodeAndEndNodes();
|
||||
} else {
|
||||
_jurisdictionRoot = nullptr;
|
||||
_jurisdictionEndNodes.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -304,7 +304,7 @@ bool isAncestorOf(const unsigned char* possibleAncestor, const unsigned char* po
|
|||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<unsigned char> hexStringToOctalCode(const QString& input) {
|
||||
OctalCodePtr hexStringToOctalCode(const QString& input) {
|
||||
const int HEX_NUMBER_BASE = 16;
|
||||
const int HEX_BYTE_SIZE = 2;
|
||||
int stringIndex = 0;
|
||||
|
|
|
@ -24,6 +24,7 @@ const int GREEN_INDEX = 1;
|
|||
const int BLUE_INDEX = 2;
|
||||
|
||||
using OctalCodePtr = std::shared_ptr<unsigned char>;
|
||||
using OctalCodePtrList = std::vector<OctalCodePtr>;
|
||||
|
||||
void printOctalCode(const unsigned char* octalCode);
|
||||
size_t bytesRequiredForCodeLength(unsigned char threeBitCodes);
|
||||
|
@ -61,6 +62,6 @@ typedef enum {
|
|||
OctalCodeComparison compareOctalCodes(const unsigned char* code1, const unsigned char* code2);
|
||||
|
||||
QString octalCodeToHexString(const unsigned char* octalCode);
|
||||
std::shared_ptr<unsigned char> hexStringToOctalCode(const QString& input);
|
||||
OctalCodePtr hexStringToOctalCode(const QString& input);
|
||||
|
||||
#endif // hifi_OctalCode_h
|
||||
|
|
Loading…
Reference in a new issue