This reverts commit 7adb9b094894a512c019b3378eb9e3c69d830edc.

The "No functional change" claim is wrong, after that commit, the
_eglGetNativePlatformFromEnv() function is now called every time instead
of just once it was called before. What's worse, when
_eglGetNativePlatform() is called from multiple threads, the static
native_platform variable may now alternate between _EGL_INVALID_PLATFORM
and some other value, which causes some of the threads to see and return
unintended result.

The old code is not exactly thread safe either, but because the code
stops changing 'native_platform' as soon as it's not
_EGL_INVALID_PLATFORM, it should not cause problems in practice.

Cc: Eric Engestrom <eric.engest...@imgtec.com>
Fixes: 7adb9b0948 "egl/display: remove unnecessary code and make it easier to 
read"
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=101252
Signed-off-by: Grazvydas Ignotas <nota...@gmail.com>
---
 src/egl/main/egldisplay.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c
index 2a1f027..6e007a1 100644
--- a/src/egl/main/egldisplay.c
+++ b/src/egl/main/egldisplay.c
@@ -178,28 +178,29 @@ _eglNativePlatformDetectNativeDisplay(void *nativeDisplay)
  * Return the native platform.  It is the platform of the EGL native types.
  */
 _EGLPlatformType
 _eglGetNativePlatform(void *nativeDisplay)
 {
-   static _EGLPlatformType native_platform;
-   char *detection_method;
-
-   native_platform = _eglGetNativePlatformFromEnv();
-   detection_method = "environment overwrite";
-
-   if (native_platform == _EGL_INVALID_PLATFORM) {
-      native_platform = _eglNativePlatformDetectNativeDisplay(nativeDisplay);
-      detection_method = "autodetected";
-   }
+   static _EGLPlatformType native_platform = _EGL_INVALID_PLATFORM;
+   char *detection_method = NULL;
 
    if (native_platform == _EGL_INVALID_PLATFORM) {
-      native_platform = _EGL_NATIVE_PLATFORM;
-      detection_method = "build-time configuration";
+      native_platform = _eglGetNativePlatformFromEnv();
+      detection_method = "environment overwrite";
+      if (native_platform == _EGL_INVALID_PLATFORM) {
+         native_platform = 
_eglNativePlatformDetectNativeDisplay(nativeDisplay);
+         detection_method = "autodetected";
+         if (native_platform == _EGL_INVALID_PLATFORM) {
+            native_platform = _EGL_NATIVE_PLATFORM;
+            detection_method = "build-time configuration";
+         }
+      }
    }
 
-   _eglLog(_EGL_DEBUG, "Native platform type: %s (%s)",
-           egl_platforms[native_platform].name, detection_method);
+   if (detection_method != NULL)
+      _eglLog(_EGL_DEBUG, "Native platform type: %s (%s)",
+              egl_platforms[native_platform].name, detection_method);
 
    return native_platform;
 }
 
 
-- 
2.7.4

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to