mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
fix bad lock, optimize some operations, clarify comment
This commit is contained in:
parent
3a7785d10f
commit
b31837168d
4 changed files with 8 additions and 5 deletions
|
@ -464,6 +464,8 @@ void AvatarManager::clearOtherAvatars() {
|
|||
{
|
||||
QWriteLocker locker(&_hashLock);
|
||||
|
||||
removedAvatars.reserve(_avatarHash.size());
|
||||
|
||||
auto avatarIterator = _avatarHash.begin();
|
||||
while (avatarIterator != _avatarHash.end()) {
|
||||
auto avatar = std::static_pointer_cast<Avatar>(avatarIterator.value());
|
||||
|
@ -484,7 +486,7 @@ void AvatarManager::clearOtherAvatars() {
|
|||
void AvatarManager::deleteAllAvatars() {
|
||||
assert(_avatarsToChangeInPhysics.empty());
|
||||
|
||||
QReadLocker locker(&_hashLock);
|
||||
QWriteLocker locker(&_hashLock);
|
||||
AvatarHash::iterator avatarIterator = _avatarHash.begin();
|
||||
while (avatarIterator != _avatarHash.end()) {
|
||||
auto avatar = std::static_pointer_cast<OtherAvatar>(avatarIterator.value());
|
||||
|
|
|
@ -205,7 +205,9 @@ private:
|
|||
|
||||
AvatarSharedPointer newSharedAvatar() override;
|
||||
|
||||
// must not be called while holding the hash lock
|
||||
// called only from the AvatarHashMap thread - cannot be called while this thread holds the
|
||||
// hash lock, since handleRemovedAvatar needs a write lock on the entity tree and the entity tree
|
||||
// frequently grabs a read lock on the hash to get a given avatar by ID
|
||||
void handleRemovedAvatar(const AvatarSharedPointer& removedAvatar,
|
||||
KillAvatarReason removalReason = KillAvatarReason::NoReason) override;
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ std::vector<AvatarSharedPointer> AvatarReplicas::takeReplicas(const QUuid& paren
|
|||
|
||||
if (it != _replicasMap.end()) {
|
||||
// take a copy of the replica shared pointers for this parent
|
||||
replicas = it->second;
|
||||
replicas.swap(it->second);
|
||||
|
||||
// erase the replicas for this parent from our map
|
||||
_replicasMap.erase(it);
|
||||
|
|
|
@ -180,8 +180,7 @@ protected:
|
|||
bool& isNew);
|
||||
virtual AvatarSharedPointer findAvatar(const QUuid& sessionUUID) const; // uses a QReadLocker on the hashLock
|
||||
virtual void removeAvatar(const QUuid& sessionUUID, KillAvatarReason removalReason = KillAvatarReason::NoReason);
|
||||
|
||||
// must not be called while holding the hash lock
|
||||
|
||||
virtual void handleRemovedAvatar(const AvatarSharedPointer& removedAvatar, KillAvatarReason removalReason = KillAvatarReason::NoReason);
|
||||
|
||||
AvatarHash _avatarHash;
|
||||
|
|
Loading…
Reference in a new issue