summaryrefslogtreecommitdiff
path: root/lib/locks.c
diff options
context:
space:
mode:
authorDaiki Ueno <ueno@gnu.org>2021-11-14 14:57:15 +0100
committerDaiki Ueno <ueno@gnu.org>2021-11-17 08:08:29 +0100
commit90bbc9b76d381bccbfe370f1926941b35b5b56ec (patch)
tree0540a1ee9079cfa755b929eea86aa15c0f6f2b34 /lib/locks.c
parentbcffed047f7a228cf99028eb2b8249e5a02eb2e6 (diff)
downloadgnutls-90bbc9b76d381bccbfe370f1926941b35b5b56ec.tar.gz
locks: use once execution for on-demand initialization of globals
This makes sure that the global variables are initialized only once. Most of those variables are initialized at ELF constructor, though a couple of occasions they are initialized on-demand: the global keylog file pointer and TPM2 TCTI context. To properly protect the initialization this patch uses gl_once provided by Gnulib. Signed-off-by: Daiki Ueno <ueno@gnu.org>
Diffstat (limited to 'lib/locks.c')
-rw-r--r--lib/locks.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/locks.c b/lib/locks.c
index 3c05e4d988..146a806132 100644
--- a/lib/locks.c
+++ b/lib/locks.c
@@ -117,3 +117,12 @@ gnutls_rwlock_unlock(gnutls_rwlock_t rwlock)
}
return 0;
}
+
+int
+gnutls_once(gnutls_once_t once, void (*init_func) (void))
+{
+ if (unlikely(glthread_once(once, init_func))) {
+ return gnutls_assert_val(GNUTLS_E_LOCKING_ERROR);
+ }
+ return 0;
+}