[Mesa-dev] [PATCH 1/2] anv: only init locale once

Grazvydas Ignotas notasas at gmail.com
Tue May 2 18:01:07 UTC 2017


This follows the same pattern as in _mesa_initialize_context(), but uses
pthread_once instead of a mutex. The goal is to avoid problems with
multiple instances.

Signed-off-by: Grazvydas Ignotas <notasas at gmail.com>
---
 src/intel/vulkan/anv_device.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index 98352c9..92bd255 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -397,10 +397,25 @@ static const VkAllocationCallbacks default_alloc = {
    .pfnAllocation = default_alloc_func,
    .pfnReallocation = default_realloc_func,
    .pfnFree = default_free_func,
 };
 
+static pthread_once_t anv_one_time_init_control = PTHREAD_ONCE_INIT;
+
+static void
+anv_one_time_fini(void)
+{
+   _mesa_locale_fini();
+}
+
+static void
+anv_one_time_init(void)
+{
+   _mesa_locale_init();
+   atexit(anv_one_time_fini);
+}
+
 VkResult anv_CreateInstance(
     const VkInstanceCreateInfo*                 pCreateInfo,
     const VkAllocationCallbacks*                pAllocator,
     VkInstance*                                 pInstance)
 {
@@ -451,11 +466,11 @@ VkResult anv_CreateInstance(
       instance->alloc = default_alloc;
 
    instance->apiVersion = client_version;
    instance->physicalDeviceCount = -1;
 
-   _mesa_locale_init();
+   pthread_once(&anv_one_time_init_control, anv_one_time_init);
 
    VG(VALGRIND_CREATE_MEMPOOL(instance, 0, false));
 
    *pInstance = anv_instance_to_handle(instance);
 
@@ -477,12 +492,10 @@ void anv_DestroyInstance(
       anv_physical_device_finish(&instance->physicalDevice);
    }
 
    VG(VALGRIND_DESTROY_MEMPOOL(instance));
 
-   _mesa_locale_fini();
-
    vk_free(&instance->alloc, instance);
 }
 
 static VkResult
 anv_enumerate_devices(struct anv_instance *instance)
-- 
2.7.4



More information about the mesa-dev mailing list