This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

local equivalent for pthread_once() in glibc?

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   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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]