]> sourceware.org Git - glibc.git/blame - nptl/sysdeps/unix/sysv/linux/i386/pthread_once.S
Remove use of INTDEF/INTUSE in nptl
[glibc.git] / nptl / sysdeps / unix / sysv / linux / i386 / pthread_once.S
CommitLineData
4d17e683 1/* Copyright (C) 2002-2012 Free Software Foundation, Inc.
76a50749
UD
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
4
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.
9
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.
14
15 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
76a50749 18
3a4d1e1e 19#include <unwindbuf.h>
76a50749 20#include <sysdep.h>
5a8075b1 21#include <kernel-features.h>
e51deae7 22#include <lowlevellock.h>
5a8075b1 23
76a50749 24
76a50749
UD
25 .comm __fork_generation, 4, 4
26
27 .text
28
29
30 .globl __pthread_once
31 .type __pthread_once,@function
32 .align 16
3a4d1e1e 33 cfi_startproc
76a50749
UD
34__pthread_once:
35 movl 4(%esp), %ecx
36 testl $2, (%ecx)
37 jz 1f
38 xorl %eax, %eax
39 ret
40
411: pushl %ebx
3a4d1e1e
UD
42 cfi_adjust_cfa_offset (4)
43 cfi_rel_offset (3, 0)
76a50749 44 pushl %esi
3a4d1e1e
UD
45 cfi_adjust_cfa_offset (4)
46 cfi_rel_offset (6, 0)
76a50749
UD
47 movl %ecx, %ebx
48 xorl %esi, %esi
49
50 /* Not yet initialized or initialization in progress.
51 Get the fork generation counter now. */
526: movl (%ebx), %eax
53#ifdef PIC
9a1d9254 54 LOAD_PIC_REG(cx)
76a50749
UD
55#endif
56
575: movl %eax, %edx
58
59 testl $2, %eax
60 jnz 4f
61
62 andl $3, %edx
63#ifdef PIC
64 orl __fork_generation@GOTOFF(%ecx), %edx
65#else
66 orl __fork_generation, %edx
67#endif
68 orl $1, %edx
69
70 LOCK
71 cmpxchgl %edx, (%ebx)
72 jnz 5b
73
74 /* Check whether another thread already runs the initializer. */
75 testl $1, %eax
76 jz 3f /* No -> do it. */
77
78 /* Check whether the initializer execution was interrupted
79 by a fork. */
80 xorl %edx, %eax
81 testl $0xfffffffc, %eax
82 jnz 3f /* Different for generation -> run initializer. */
83
84 /* Somebody else got here first. Wait. */
5a8075b1
UD
85#ifdef __ASSUME_PRIVATE_FUTEX
86 movl $FUTEX_WAIT|FUTEX_PRIVATE_FLAG, %ecx
87#else
88# if FUTEX_WAIT == 0
89 movl %gs:PRIVATE_FUTEX, %ecx
90# else
91 movl $FUTEX_WAIT, %ecx
92 orl %gs:PRIVATE_FUTEX, %ecx
93# endif
94#endif
76a50749 95 movl $SYS_futex, %eax
097eca29 96 ENTER_KERNEL
76a50749
UD
97 jmp 6b
98
993: /* Call the initializer function after setting up the
3a4d1e1e
UD
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
104 guaranteed. */
105 subl $UNWINDBUFSIZE+8, %esp
106 cfi_adjust_cfa_offset (UNWINDBUFSIZE+8)
107 movl %ecx, %ebx /* PIC register value. */
108
109 leal 8+UWJMPBUF(%esp), %eax
76a50749 110 movl $0, 4(%esp)
3a4d1e1e
UD
111 movl %eax, (%esp)
112 call __sigsetjmp@PLT
e9a7bbab 113 testl %eax, %eax
3a4d1e1e 114 jne 7f
76a50749 115
3a4d1e1e 116 leal 8(%esp), %eax
da0c02ee 117 call HIDDEN_JUMPTARGET(__pthread_register_cancel)
3a4d1e1e
UD
118
119 /* Call the user-provided initialization function. */
120 call *24+UNWINDBUFSIZE(%esp)
121
122 /* Pop the cleanup handler. */
123 leal 8(%esp), %eax
da0c02ee 124 call HIDDEN_JUMPTARGET(__pthread_unregister_cancel)
3a4d1e1e
UD
125 addl $UNWINDBUFSIZE+8, %esp
126 cfi_adjust_cfa_offset (-UNWINDBUFSIZE-8)
76a50749
UD
127
128 /* Sucessful run of the initializer. Signal that we are done. */
3a4d1e1e 129 movl 12(%esp), %ebx
76a50749 130 LOCK
ccf1d573 131 addl $1, (%ebx)
76a50749
UD
132
133 /* Wake up all other threads. */
134 movl $0x7fffffff, %edx
5a8075b1
UD
135#ifdef __ASSUME_PRIVATE_FUTEX
136 movl $FUTEX_WAKE|FUTEX_PRIVATE_FLAG, %ecx
137#else
76a50749 138 movl $FUTEX_WAKE, %ecx
5a8075b1
UD
139 orl %gs:PRIVATE_FUTEX, %ecx
140#endif
76a50749 141 movl $SYS_futex, %eax
097eca29 142 ENTER_KERNEL
76a50749
UD
143
1444: popl %esi
3a4d1e1e
UD
145 cfi_adjust_cfa_offset (-4)
146 cfi_restore (6)
76a50749 147 popl %ebx
3a4d1e1e
UD
148 cfi_adjust_cfa_offset (-4)
149 cfi_restore (3)
76a50749
UD
150 xorl %eax, %eax
151 ret
152
3a4d1e1e
UD
1537: /* __sigsetjmp returned for the second time. */
154 movl 20+UNWINDBUFSIZE(%esp), %ebx
155 cfi_adjust_cfa_offset (UNWINDBUFSIZE+16)
156 cfi_offset (3, -8)
157 cfi_offset (6, -12)
defd1870 158 movl $0, (%ebx)
76a50749 159
76a50749 160 movl $0x7fffffff, %edx
5a8075b1
UD
161#ifdef __ASSUME_PRIVATE_FUTEX
162 movl $FUTEX_WAKE|FUTEX_PRIVATE_FLAG, %ecx
163#else
76a50749 164 movl $FUTEX_WAKE, %ecx
5a8075b1
UD
165 orl %gs:PRIVATE_FUTEX, %ecx
166#endif
76a50749 167 movl $SYS_futex, %eax
097eca29 168 ENTER_KERNEL
76a50749 169
3a4d1e1e 170 leal 8(%esp), %eax
da0c02ee 171 call HIDDEN_JUMPTARGET (__pthread_unwind_next)
3a4d1e1e
UD
172 /* NOTREACHED */
173 hlt
174 cfi_endproc
175 .size __pthread_once,.-__pthread_once
176
4d17e683
AS
177hidden_def (__pthread_once)
178strong_alias (__pthread_once, pthread_once)
This page took 0.28448 seconds and 5 git commands to generate.