123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- #include "pthreadP.h"
- #include <lowlevellock.h>
- unsigned long int __fork_generation attribute_hidden;
- static void
- clear_once_control (void *arg)
- {
- pthread_once_t *once_control = (pthread_once_t *) arg;
- *once_control = 0;
- lll_futex_wake (once_control, INT_MAX, LLL_PRIVATE);
- }
- int
- attribute_hidden
- __pthread_once (pthread_once_t *once_control, void (*init_routine) (void))
- {
- for (;;)
- {
- int oldval;
- int newval;
-
- do
- {
- newval = __fork_generation | 1;
- oldval = *once_control;
- if (oldval & 2)
- break;
- } while (atomic_compare_and_exchange_val_acq (once_control, newval, oldval) != oldval);
-
- if ((oldval & 2) != 0)
- return 0;
-
- if ((oldval & 1) == 0)
- break;
-
- if (oldval != newval)
- break;
-
- lll_futex_wait (once_control, oldval, LLL_PRIVATE);
- }
-
- pthread_cleanup_push (clear_once_control, once_control);
- init_routine ();
- pthread_cleanup_pop (0);
-
- *once_control = __fork_generation | 2;
-
- lll_futex_wake (once_control, INT_MAX, LLL_PRIVATE);
- return 0;
- }
- weak_alias (__pthread_once, pthread_once)
- strong_alias (__pthread_once, __pthread_once_internal)
- #if defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__PIC__)
- const void *include_pthread_getspecific attribute_hidden = pthread_getspecific;
- const void *include_pthread_setspecific attribute_hidden = pthread_setspecific;
- const void *include_pthread_key_create attribute_hidden = pthread_key_create;
- #endif
|