1 /* Copyright (C) 2003, 2004, 2007 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
18 #include <unwindbuf.h>
20 #include <bits/kernel-features.h>
21 #include <lowlevellock.h>
22 #include <tcb-offsets.h>
23 #include "lowlevel-atomic.h"
26 .comm __fork_generation, 4, 4
30 .type __pthread_once,@function
31 .protected __pthread_once
43 cfi_adjust_cfa_offset (4)
44 cfi_rel_offset (r12, 0)
46 cfi_adjust_cfa_offset (4)
47 cfi_rel_offset (r9, 0)
49 cfi_adjust_cfa_offset (4)
50 cfi_rel_offset (r8, 0)
52 cfi_adjust_cfa_offset (4)
53 cfi_rel_offset (pr, 0)
57 /* Not yet initialized or initialization in progress.
58 Get the fork generation counter now. */
82 CMPXCHG (r5, @r4, r3, r2)
85 /* Check whether another thread already runs the initializer. */
88 bt 3f /* No -> do it. */
90 /* Check whether the initializer execution was interrupted
93 mov #-4, r1 /* -4 = 0xfffffffc */
95 bf 3f /* Different for generation -> run initializer. */
97 /* Somebody else got here first. Wait. */
98 #ifdef __ASSUME_PRIVATE_FUTEX
99 mov #(FUTEX_PRIVATE_FLAG|FUTEX_WAIT), r5
122 .long _GLOBAL_OFFSET_TABLE_
125 .long __fork_generation@GOTOFF
128 .long __fork_generation
132 /* Call the initializer function after setting up the
133 cancellation handler. Note that it is not possible here
134 to use the unwind-based cleanup handling. This would require
135 that the user-provided function and all the code it calls
136 is compiled with exceptions. Unfortunately this cannot be
138 add #-UNWINDBUFSIZE, r15
139 cfi_adjust_cfa_offset (UNWINDBUFSIZE)
141 mov.l .Lsigsetjmp, r1
155 /* Call the user-provided initialization function. */
159 /* Pop the cleanup handler. */
165 add #UNWINDBUFSIZE, r15
166 cfi_adjust_cfa_offset (-UNWINDBUFSIZE)
168 /* Sucessful run of the initializer. Signal that we are done. */
170 /* Wake up all other threads. */
172 #ifdef __ASSUME_PRIVATE_FUTEX
173 mov #(FUTEX_PRIVATE_FLAG|FUTEX_WAKE), r5
184 shlr r6 /* r6 = 0x7fffffff */
193 cfi_adjust_cfa_offset (-4)
196 cfi_adjust_cfa_offset (-4)
199 cfi_adjust_cfa_offset (-4)
202 cfi_adjust_cfa_offset (-4)
208 /* __sigsetjmp returned for the second time. */
209 cfi_adjust_cfa_offset (UNWINDBUFSIZE+16)
217 #ifdef __ASSUME_PRIVATE_FUTEX
218 mov #(FUTEX_PRIVATE_FLAG|FUTEX_WAKE), r5
229 shlr r6 /* r6 = 0x7fffffff */
243 #ifndef __ASSUME_PRIVATE_FUTEX
245 .word PRIVATE_FUTEX - TLS_PRE_TCB_SIZE
249 .long __sigsetjmp@PLT-(.Lsigsetjmp0-.)
251 .long HIDDEN_JUMPTARGET(__pthread_register_cancel)-.Lcpush0
253 .long HIDDEN_JUMPTARGET(__pthread_unregister_cancel)-.Lcpop0
255 .long HIDDEN_JUMPTARGET(__pthread_unwind_next)-.Lunext0
256 .size __pthread_once,.-__pthread_once
258 .globl __pthread_once_internal
259 __pthread_once_internal = __pthread_once
262 pthread_once = __pthread_once