diff options
author | Daiki Ueno <dueno@redhat.com> | 2018-07-20 13:11:36 +0200 |
---|---|---|
committer | Daiki Ueno <ueno@gnu.org> | 2018-08-10 10:11:24 +0200 |
commit | f04c2a84ad2a017a778fa2f23719318acb9ca89f (patch) | |
tree | 3fe93175e0966d29d3bf015c9bb9dd7498e65870 | |
parent | 5b18e77e9dbb6a598812427ba07ad6df63eb7a67 (diff) |
common, p11-kit, trust: Use pthread_once only when necessary
If the ELF constructor is usable, we don't really need the once-init
function because it is guaranteed that the code runs only once in the
constructor.
-rw-r--r-- | common/library.c | 4 | ||||
-rw-r--r-- | common/library.h | 10 | ||||
-rw-r--r-- | p11-kit/client-init.c | 2 | ||||
-rw-r--r-- | p11-kit/proxy-init.c | 2 | ||||
-rw-r--r-- | trust/module.c | 2 |
5 files changed, 16 insertions, 4 deletions
diff --git a/common/library.c b/common/library.c index 465b35d..cde8384 100644 --- a/common/library.c +++ b/common/library.c @@ -71,8 +71,10 @@ p11_mutex_t p11_virtual_mutex; #endif #ifdef OS_UNIX +#ifndef __GNUC__ pthread_once_t p11_library_once = PTHREAD_ONCE_INIT; #endif +#endif unsigned int p11_forkid = 1; @@ -146,7 +148,7 @@ p11_library_init_impl (void) void p11_library_init (void) { - p11_library_init_once (); + p11_library_init_impl (); } void diff --git a/common/library.h b/common/library.h index c3840f8..0a779b0 100644 --- a/common/library.h +++ b/common/library.h @@ -59,11 +59,21 @@ extern unsigned int p11_forkid; #define p11_library_init_once() #else /* !OS_WIN32 */ + +#ifdef __GNUC__ + +/* No implementation, because done by the ELF constructor */ +#define p11_library_init_once() + +#else + extern pthread_once_t p11_library_once; #define p11_library_init_once() \ pthread_once (&p11_library_once, p11_library_init_impl); +#endif /* !__GNUC__ */ + void p11_library_init_impl (void); #endif /* !OS_WIN32 */ diff --git a/p11-kit/client-init.c b/p11-kit/client-init.c index d016053..74e8905 100644 --- a/p11-kit/client-init.c +++ b/p11-kit/client-init.c @@ -64,7 +64,7 @@ __attribute__((constructor)) void _p11_kit_init (void) { - p11_library_init_once (); + p11_library_init (); } #ifdef __GNUC__ diff --git a/p11-kit/proxy-init.c b/p11-kit/proxy-init.c index 397949b..118478f 100644 --- a/p11-kit/proxy-init.c +++ b/p11-kit/proxy-init.c @@ -53,7 +53,7 @@ __attribute__((constructor)) void _p11_kit_init (void) { - p11_library_init_once (); + p11_library_init (); } #ifdef __GNUC__ diff --git a/trust/module.c b/trust/module.c index 82a3fdf..fc67a4d 100644 --- a/trust/module.c +++ b/trust/module.c @@ -1845,7 +1845,7 @@ __attribute__((constructor)) void p11_trust_module_init (void) { - p11_library_init_once (); + p11_library_init (); } #ifdef __GNUC__ |