#include <stdlib.h>
#include <string.h>
#include "c11/threads.h"
+#include "util/u_atomic.h"
#include "eglcontext.h"
#include "eglcurrent.h"
_eglGetNativePlatform(void *nativeDisplay)
{
static _EGLPlatformType native_platform = _EGL_INVALID_PLATFORM;
+ _EGLPlatformType detected_platform = native_platform;
- if (native_platform == _EGL_INVALID_PLATFORM) {
+ if (detected_platform == _EGL_INVALID_PLATFORM) {
const char *detection_method;
- native_platform = _eglGetNativePlatformFromEnv();
+ detected_platform = _eglGetNativePlatformFromEnv();
detection_method = "environment overwrite";
- if (native_platform == _EGL_INVALID_PLATFORM) {
- native_platform = _eglNativePlatformDetectNativeDisplay(nativeDisplay);
+ if (detected_platform == _EGL_INVALID_PLATFORM) {
+ detected_platform = _eglNativePlatformDetectNativeDisplay(nativeDisplay);
detection_method = "autodetected";
}
- if (native_platform == _EGL_INVALID_PLATFORM) {
- native_platform = _EGL_NATIVE_PLATFORM;
+ if (detected_platform == _EGL_INVALID_PLATFORM) {
+ detected_platform = _EGL_NATIVE_PLATFORM;
detection_method = "build-time configuration";
}
_eglLog(_EGL_DEBUG, "Native platform type: %s (%s)",
- egl_platforms[native_platform].name, detection_method);
+ egl_platforms[detected_platform].name, detection_method);
+
+ p_atomic_cmpxchg(&native_platform, _EGL_INVALID_PLATFORM,
+ detected_platform);
}
return native_platform;