This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
local equivalent for pthread_once() in glibc?
- From: Chris Aoki <christopher dot aoki at oracle dot com>
- To: libc-help at sourceware dot org
- Cc: Chris Aoki <christopher dot aoki at oracle dot com>
- Date: Tue, 25 Apr 2017 10:50:41 -0700
- Subject: local equivalent for pthread_once() in glibc?
- Authentication-results: sourceware.org; auth=none
I have a question about glibc internals.
Is there a private glibc function equivalent to pthread_once()?
I have a structure that is frequently accessed after initialization
so putting a lock around initialization and a check for initialization
would add considerable overhead. Normally one would use pthread_once()
in this situation, but my colleagues tell me that adding a reference to an
external function is prohibited within libc.so. I see a macro __libc_once()
but it does not appear to synchronize:
/* Define once control variable. */
#define __libc_once_define(CLASS, NAME) CLASS int NAME = 0
/* Call handler iff the first call. */
#define __libc_once(ONCE_CONTROL, INIT_FUNCTION) \
do { \
if ((ONCE_CONTROL) == 0) { \
INIT_FUNCTION (); \
(ONCE_CONTROL) = 1; \
} \
} while (0)
Any clues appreciated. Thanks
Chris Aoki