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, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 #include <unwindbuf.h>
21 #include <bits/kernel-features.h>
22 #include <lowlevellock.h>
23 #include <tcb-offsets.h>
24 #include "lowlevel-atomic.h"
27 .comm __fork_generation, 4, 4
31 .type __pthread_once,@function
32 .protected __pthread_once
44 cfi_adjust_cfa_offset (4)
45 cfi_rel_offset (r12, 0)
47 cfi_adjust_cfa_offset (4)
48 cfi_rel_offset (r9, 0)
50 cfi_adjust_cfa_offset (4)
51 cfi_rel_offset (r8, 0)
53 cfi_adjust_cfa_offset (4)
54 cfi_rel_offset (pr, 0)
58 /* Not yet initialized or initialization in progress.
59 Get the fork generation counter now. */
83 CMPXCHG (r5, @r4, r3, r2)
86 /* Check whether another thread already runs the initializer. */
89 bt 3f /* No -> do it. */
91 /* Check whether the initializer execution was interrupted
94 mov #-4, r1 /* -4 = 0xfffffffc */
96 bf 3f /* Different for generation -> run initializer. */
98 /* Somebody else got here first. Wait. */
99 #ifdef __ASSUME_PRIVATE_FUTEX
100 mov #(FUTEX_PRIVATE_FLAG|FUTEX_WAIT), r5
123 .long _GLOBAL_OFFSET_TABLE_
126 .long __fork_generation@GOTOFF
129 .long __fork_generation
133 /* Call the initializer function after setting up the
134 cancellation handler. Note that it is not possible here
135 to use the unwind-based cleanup handling. This would require
136 that the user-provided function and all the code it calls
137 is compiled with exceptions. Unfortunately this cannot be
139 add #-UNWINDBUFSIZE, r15
140 cfi_adjust_cfa_offset (UNWINDBUFSIZE)
142 mov.l .Lsigsetjmp, r1
156 /* Call the user-provided initialization function. */
160 /* Pop the cleanup handler. */
166 add #UNWINDBUFSIZE, r15
167 cfi_adjust_cfa_offset (-UNWINDBUFSIZE)
169 /* Sucessful run of the initializer. Signal that we are done. */
171 /* Wake up all other threads. */
173 #ifdef __ASSUME_PRIVATE_FUTEX
174 mov #(FUTEX_PRIVATE_FLAG|FUTEX_WAKE), r5
185 shlr r6 /* r6 = 0x7fffffff */
194 cfi_adjust_cfa_offset (-4)
197 cfi_adjust_cfa_offset (-4)
200 cfi_adjust_cfa_offset (-4)
203 cfi_adjust_cfa_offset (-4)
209 /* __sigsetjmp returned for the second time. */
210 cfi_adjust_cfa_offset (UNWINDBUFSIZE+16)
218 #ifdef __ASSUME_PRIVATE_FUTEX
219 mov #(FUTEX_PRIVATE_FLAG|FUTEX_WAKE), r5
230 shlr r6 /* r6 = 0x7fffffff */
244 #ifndef __ASSUME_PRIVATE_FUTEX
246 .word PRIVATE_FUTEX - TLS_PRE_TCB_SIZE
250 .long __sigsetjmp@PLT-(.Lsigsetjmp0-.)
252 .long HIDDEN_JUMPTARGET(__pthread_register_cancel)-.Lcpush0
254 .long HIDDEN_JUMPTARGET(__pthread_unregister_cancel)-.Lcpop0
256 .long HIDDEN_JUMPTARGET(__pthread_unwind_next)-.Lunext0
257 .size __pthread_once,.-__pthread_once
259 .globl __pthread_once_internal
260 __pthread_once_internal = __pthread_once
263 pthread_once = __pthread_once