From f04c2a84ad2a017a778fa2f23719318acb9ca89f Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Fri, 20 Jul 2018 13:11:36 +0200 Subject: 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. --- common/library.c | 4 +++- common/library.h | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'common') 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 */ -- cgit v1.1