Skip to content

Commit

Permalink
Revert AnnotationRegistry to on-demand static (#2476)
Browse files Browse the repository at this point in the history
  • Loading branch information
gwaldron committed Mar 21, 2024
1 parent 4af7f87 commit 2586322
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
5 changes: 1 addition & 4 deletions src/osgEarth/AnnotationRegistry
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#ifndef OSGEARTH_ANNO_REGISTRY_H
#define OSGEARTH_ANNO_REGISTRY_H 1
#pragma once

#include <osgEarth/AnnotationNode>
#include <osgEarth/MapNode>
Expand Down Expand Up @@ -108,5 +107,3 @@ namespace osgEarth { namespace Util
};

} }

#endif // OSGEARTH_ANNO_FEATURE_NODE_H
18 changes: 14 additions & 4 deletions src/osgEarth/AnnotationRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,20 @@ namespace
AnnotationRegistry*
AnnotationRegistry::instance()
{
return Registry::instance()->getOrCreate<AnnotationRegistry>(
"oe.AnnotationRegistry", []() {
return new AnnotationRegistry();
});
// OK to be in the local scope since this gets called at static init time
// by the OSGEARTH_REGISTER_ANNOTATION macro
static AnnotationRegistry* s_singleton = nullptr;
static std::mutex s_singletonMutex;

if (!s_singleton)
{
std::lock_guard<std::mutex> lock(s_singletonMutex);
if (!s_singleton)
{
s_singleton = new AnnotationRegistry();
}
}
return s_singleton;
}


Expand Down

0 comments on commit 2586322

Please sign in to comment.