Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Mutex guard annotation manager for cross thread usage #9220

Merged
merged 1 commit into from
Jun 13, 2017

Conversation

ivovandongen
Copy link
Contributor

Alternative for #9208 to make annotations thread safe for asynchronous rendering (#8820)

@ivovandongen ivovandongen self-assigned this Jun 8, 2017
@ivovandongen ivovandongen added the Core The cross-platform C++ core, aka mbgl label Jun 8, 2017
@@ -68,13 +74,15 @@ void AnnotationManager::add(const AnnotationID& id, const FillAnnotation& annota
Update AnnotationManager::update(const AnnotationID& id, const SymbolAnnotation& annotation, const uint8_t maxZoom) {
Update result = Update::Nothing;

mutex.lock();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manual locking/unlocking will leave a stranded lock in the early exit case. (It's an error case, but still best not to corrupt the object internals.)

auto it = shapeAnnotations.find(id);
if (it == shapeAnnotations.end()) {
assert(false); // Attempt to update a non-existent shape annotation
return Update::Nothing;
}
mutex.unlock();

removeAndAdd(id, annotation, maxZoom);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a lock in removeAndAdd around both the remove and add, not merely a lock in add and a lock in remove. Otherwise, a tile could get updated in between the remove and the add, producing a flickering annotation.

@ivovandongen
Copy link
Contributor Author

@jfirebaugh Thanks for the review. I've factored out a private remove method that is reused by the removeAnnotation and removeAndAdd methods. Locking is now on all public methods.

@ivovandongen ivovandongen mentioned this pull request Jun 12, 2017
28 tasks
@ivovandongen ivovandongen merged commit 672ba51 into master Jun 13, 2017
@ivovandongen ivovandongen deleted the annotation-manager-mutexed branch June 13, 2017 07:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Core The cross-platform C++ core, aka mbgl
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants