gallium/osmesa: Fix data race on setting up the ST API.
authorEric Anholt <eric@anholt.net>
Wed, 2 Dec 2020 23:10:51 +0000 (15:10 -0800)
committerEric Anholt <eric@anholt.net>
Sat, 5 Dec 2020 00:00:56 +0000 (16:00 -0800)
We're going to need it anyway, put it in the same call_once as the ST
manager.

Closes: #880
Reviewed-by: Adam Jackson <ajax@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7886>

src/gallium/frontends/osmesa/osmesa.c

index 19d7078..5ce5f7b 100644 (file)
@@ -131,21 +131,8 @@ osmesa_st_get_param(struct st_manager *smapi, enum st_manager_param param)
    return 0;
 }
 
-
-/**
- * Create/return singleton st_api object.
- */
-static struct st_api *
-get_st_api(void)
-{
-   static struct st_api *stapi = NULL;
-   if (!stapi) {
-      stapi = st_gl_api_create();
-   }
-   return stapi;
-}
-
 static struct st_manager *stmgr = NULL;
+static struct st_api *stapi = NULL;
 
 static void
 create_st_manager(void)
@@ -156,6 +143,8 @@ create_st_manager(void)
       stmgr->get_param = osmesa_st_get_param;
       stmgr->get_egl_image = NULL;
    }
+
+   stapi = st_gl_api_create();
 }
 
 /**
@@ -171,6 +160,16 @@ get_st_manager(void)
    return stmgr;
 }
 
+/**
+ * Create/return singleton st_api object.
+ */
+static struct st_api *
+get_st_api(void)
+{
+   get_st_manager();
+   return stapi;
+}
+
 /* Reads the color or depth buffer from the backing context to either the user storage
  * (color buffer) or our temporary (z/s)
  */
@@ -500,8 +499,6 @@ osmesa_create_buffer(enum pipe_format color_format,
 static void
 osmesa_destroy_buffer(struct osmesa_buffer *osbuffer)
 {
-   struct st_api *stapi = get_st_api();
-
    /*
     * Notify the state manager that the associated framebuffer interface
     * is no longer valid.