summaryrefslogtreecommitdiff
path: root/src/mbgl/platform
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2015-05-12 16:11:15 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-05-13 19:01:58 -0700
commit7d4f12434e393558344d053dc5809ce586d3fbbd (patch)
tree9a1f55c52fedbb2a5a8c76bbab44f920d7915918 /src/mbgl/platform
parenta2344c36c372445ee230832a0b742ac5ee739eb1 (diff)
downloadqtlocation-mapboxgl-7d4f12434e393558344d053dc5809ce586d3fbbd.tar.gz
Ensure call-once semantics inside InitializeExtensions
Diffstat (limited to 'src/mbgl/platform')
-rw-r--r--src/mbgl/platform/gl.cpp32
1 files changed, 19 insertions, 13 deletions
diff --git a/src/mbgl/platform/gl.cpp b/src/mbgl/platform/gl.cpp
index 3d8a237c70..76be580b91 100644
--- a/src/mbgl/platform/gl.cpp
+++ b/src/mbgl/platform/gl.cpp
@@ -1,5 +1,7 @@
#include <mbgl/platform/gl.hpp>
+#include <mutex>
+
namespace mbgl {
namespace gl {
@@ -8,22 +10,26 @@ std::vector<ExtensionFunctionBase*>& ExtensionFunctionBase::functions() {
return functions;
}
+static std::once_flag initializeExtensionsOnce;
+
void InitializeExtensions(glProc (*getProcAddress)(const char *)) {
- const char * extensionsPtr = reinterpret_cast<const char *>(
- MBGL_CHECK_ERROR(glGetString(GL_EXTENSIONS)));
-
- if (!extensionsPtr)
- return;
-
- const std::string extensions = extensionsPtr;
- for (auto fn : ExtensionFunctionBase::functions()) {
- for (auto probe : fn->probes) {
- if (extensions.find(probe.first) != std::string::npos) {
- fn->ptr = getProcAddress(probe.second);
- break;
+ std::call_once(initializeExtensionsOnce, [getProcAddress] {
+ const char * extensionsPtr = reinterpret_cast<const char *>(
+ MBGL_CHECK_ERROR(glGetString(GL_EXTENSIONS)));
+
+ if (!extensionsPtr)
+ return;
+
+ const std::string extensions = extensionsPtr;
+ for (auto fn : ExtensionFunctionBase::functions()) {
+ for (auto probe : fn->probes) {
+ if (extensions.find(probe.first) != std::string::npos) {
+ fn->ptr = getProcAddress(probe.second);
+ break;
+ }
}
}
- }
+ });
}
void checkError(const char *cmd, const char *file, int line) {