summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2021-06-30 23:56:26 +0200
committerThomas Haller <thaller@redhat.com>2021-07-05 15:10:44 +0200
commit87d0e73e93c6b55aac3e8bd8ef530177ede4c42f (patch)
tree2c055562222b9c4100280f07176d8cef3fbf6fb4
parent07cd62924536c4d836daf92d0af62873f3eaf84f (diff)
downloadNetworkManager-87d0e73e93c6b55aac3e8bd8ef530177ede4c42f.tar.gz
glib-aux: avoid accessing thread-local variable in a loop
Dunno whether the compiler can optimize this out. Assign to an auto variable. (cherry picked from commit 94121a1b48b67ede0ebe8dec336da18e05d403eb)
-rw-r--r--src/libnm-glib-aux/nm-random-utils.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/libnm-glib-aux/nm-random-utils.c b/src/libnm-glib-aux/nm-random-utils.c
index 8c364cb543..f622b28411 100644
--- a/src/libnm-glib-aux/nm-random-utils.c
+++ b/src/libnm-glib-aux/nm-random-utils.c
@@ -203,7 +203,8 @@ fd_open:
}
if (!urandom_success) {
- static _nm_thread_local GRand *rand = NULL;
+ static _nm_thread_local GRand *rand_tls = NULL;
+ GRand * rand;
gsize i;
int j;
@@ -214,8 +215,10 @@ fd_open:
*/
has_high_quality = FALSE;
+ rand = rand_tls;
if (G_UNLIKELY(!rand)) {
- rand = _rand_create_thread_local();
+ rand = _rand_create_thread_local();
+ rand_tls = rand;
nm_utils_thread_local_register_destroy(rand, (GDestroyNotify) g_rand_free);
}