1 /* Copyright (C) 2002-2014 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <unwindbuf.h>
21 #include <kernel-features.h>
22 #include <lowlevellock.h>
25 .comm __fork_generation, 4, 4
31 .type __pthread_once,@function
42 cfi_adjust_cfa_offset (4)
45 cfi_adjust_cfa_offset (4)
50 /* Not yet initialized or initialization in progress.
51 Get the fork generation counter now. */
64 orl __fork_generation@GOTOFF(%ecx), %edx
66 orl __fork_generation, %edx
74 /* Check whether another thread already runs the initializer. */
76 jz 3f /* No -> do it. */
78 /* Check whether the initializer execution was interrupted
81 testl $0xfffffffc, %eax
82 jnz 3f /* Different for generation -> run initializer. */
84 /* Somebody else got here first. Wait. */
85 #ifdef __ASSUME_PRIVATE_FUTEX
86 movl $FUTEX_WAIT|FUTEX_PRIVATE_FLAG, %ecx
89 movl %gs:PRIVATE_FUTEX, %ecx
91 movl $FUTEX_WAIT, %ecx
92 orl %gs:PRIVATE_FUTEX, %ecx
99 3: /* Call the initializer function after setting up the
100 cancellation handler. Note that it is not possible here
101 to use the unwind-based cleanup handling. This would require
102 that the user-provided function and all the code it calls
103 is compiled with exceptions. Unfortunately this cannot be
105 subl $UNWINDBUFSIZE+8, %esp
106 cfi_adjust_cfa_offset (UNWINDBUFSIZE+8)
107 movl %ecx, %ebx /* PIC register value. */
109 leal 8+UWJMPBUF(%esp), %eax
117 call HIDDEN_JUMPTARGET(__pthread_register_cancel)
119 /* Call the user-provided initialization function. */
120 call *24+UNWINDBUFSIZE(%esp)
122 /* Pop the cleanup handler. */
124 call HIDDEN_JUMPTARGET(__pthread_unregister_cancel)
125 addl $UNWINDBUFSIZE+8, %esp
126 cfi_adjust_cfa_offset (-UNWINDBUFSIZE-8)
128 /* Sucessful run of the initializer. Signal that we are done. */
133 /* Wake up all other threads. */
134 movl $0x7fffffff, %edx
135 #ifdef __ASSUME_PRIVATE_FUTEX
136 movl $FUTEX_WAKE|FUTEX_PRIVATE_FLAG, %ecx
138 movl $FUTEX_WAKE, %ecx
139 orl %gs:PRIVATE_FUTEX, %ecx
141 movl $SYS_futex, %eax
145 cfi_adjust_cfa_offset (-4)
148 cfi_adjust_cfa_offset (-4)
153 7: /* __sigsetjmp returned for the second time. */
154 movl 20+UNWINDBUFSIZE(%esp), %ebx
155 cfi_adjust_cfa_offset (UNWINDBUFSIZE+16)
160 movl $0x7fffffff, %edx
161 #ifdef __ASSUME_PRIVATE_FUTEX
162 movl $FUTEX_WAKE|FUTEX_PRIVATE_FLAG, %ecx
164 movl $FUTEX_WAKE, %ecx
165 orl %gs:PRIVATE_FUTEX, %ecx
167 movl $SYS_futex, %eax
171 call HIDDEN_JUMPTARGET (__pthread_unwind_next)
175 .size __pthread_once,.-__pthread_once
177 hidden_def (__pthread_once)
178 strong_alias (__pthread_once, pthread_once)