From: Eric Anholt Date: Wed, 3 Jul 2019 18:28:49 +0000 (-0700) Subject: gallium/osmesa: Fix a race in creating the stmgr. X-Git-Tag: upstream/19.3.0~2223 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9e7eb9780aaac0737095a7ce87e8af336ea42f86;p=platform%2Fupstream%2Fmesa.git gallium/osmesa: Fix a race in creating the stmgr. Noticed while looking at other OSMesa bugs. Reviewed-by: Timothy Arceri --- diff --git a/src/gallium/state_trackers/osmesa/osmesa.c b/src/gallium/state_trackers/osmesa/osmesa.c index 41ff921..8854987 100644 --- a/src/gallium/state_trackers/osmesa/osmesa.c +++ b/src/gallium/state_trackers/osmesa/osmesa.c @@ -50,6 +50,7 @@ #include +#include #include "GL/osmesa.h" #include "glapi/glapi.h" /* for OSMesaGetProcAddress below */ @@ -149,6 +150,18 @@ get_st_api(void) return stapi; } +static struct st_manager *stmgr = NULL; + +static void +create_st_manager(void) +{ + stmgr = CALLOC_STRUCT(st_manager); + if (stmgr) { + stmgr->screen = osmesa_create_screen(); + stmgr->get_param = osmesa_st_get_param; + stmgr->get_egl_image = NULL; + } +} /** * Create/return a singleton st_manager object. @@ -156,15 +169,10 @@ get_st_api(void) static struct st_manager * get_st_manager(void) { - static struct st_manager *stmgr = NULL; - if (!stmgr) { - stmgr = CALLOC_STRUCT(st_manager); - if (stmgr) { - stmgr->screen = osmesa_create_screen(); - stmgr->get_param = osmesa_st_get_param; - stmgr->get_egl_image = NULL; - } - } + static once_flag create_once_flag = ONCE_FLAG_INIT; + + call_once(&create_once_flag, create_st_manager); + return stmgr; }