summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Janes <[email protected]>2016-04-12 11:52:53 -0700
committerMark Janes <[email protected]>2016-04-12 15:38:43 -0700
commit9e351e077befbdc179f7926edd8b5dde02f20494 (patch)
treedc80a074550794c650d27c7f298fca348fa3a05a
parent3aa1a5ee8841fa93da5617630601e8110d428e8a (diff)
util: Fix race condition on libgcrypt initialization
Fixes intermittent Vulkan CTS failures within the test groups: dEQP-VK.api.object_management.multithreaded_per_thread_device dEQP-VK.api.object_management.multithreaded_per_thread_resources dEQP-VK.api.object_management.multithreaded_shared_resources Signed-off-by: Mark Janes <[email protected]> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=94904 Reviewed-by: Edward O'Callaghan <[email protected]> Reviewed-by: Jason Ekstrand <[email protected]>
-rw-r--r--src/util/mesa-sha1.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/util/mesa-sha1.c b/src/util/mesa-sha1.c
index faa1c871b5d..ca6b89bb2c7 100644
--- a/src/util/mesa-sha1.c
+++ b/src/util/mesa-sha1.c
@@ -175,21 +175,24 @@ _mesa_sha1_final(struct mesa_sha1 *ctx, unsigned char result[20])
#elif defined(HAVE_SHA1_IN_LIBGCRYPT) /* Use libgcrypt for SHA1 */
#include <gcrypt.h>
+#include "c11/threads.h"
+
+static void _mesa_libgcrypt_init(void)
+{
+ if (!gcry_check_version(NULL))
+ return NULL;
+ gcry_control(GCRYCTL_DISABLE_SECMEM, 0);
+ gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
+}
struct mesa_sha1 *
_mesa_sha1_init(void)
{
- static int init;
+ static once_flag flag = ONCE_FLAG_INIT;
gcry_md_hd_t h;
gcry_error_t err;
- if (!init) {
- if (!gcry_check_version(NULL))
- return NULL;
- gcry_control(GCRYCTL_DISABLE_SECMEM, 0);
- gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
- init = 1;
- }
+ call_once(&flag, _mesa_libgcrypt_init);
err = gcry_md_open(&h, GCRY_MD_SHA1, 0);
if (err)