1 /* Copyright (C) 2003-2023 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 <https://www.gnu.org/licenses/>. */
19 #include <shlib-compat.h>
24 #include <support/xunistd.h>
26 /* LinuxThreads pthread_cleanup_{push,pop} helpers. */
27 extern void _pthread_cleanup_push (struct _pthread_cleanup_buffer
*__buffer
,
28 void (*__routine
) (void *),
30 compat_symbol_reference (libpthread
, _pthread_cleanup_push
,
31 _pthread_cleanup_push
, GLIBC_2_0
);
32 extern void _pthread_cleanup_pop (struct _pthread_cleanup_buffer
*__buffer
,
34 compat_symbol_reference (libpthread
, _pthread_cleanup_pop
,
35 _pthread_cleanup_pop
, GLIBC_2_0
);
38 static pthread_barrier_t b2
;
41 /* Defined in tst-cleanup4aux.c, never compiled with -fexceptions. */
42 extern void fn5 (void);
43 extern void fn7 (void);
44 extern void fn9 (void);
49 int val
= (long int) arg
;
51 printf ("clh (%d)\n", val
);
58 static __attribute__((noinline
)) void
61 int r
= pthread_barrier_wait (&b2
);
62 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
64 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
69 xread (fds
[0], &c
, 1);
73 __attribute__((noinline
)) void
76 pthread_cleanup_push (clh
, (void *) 1l);
80 pthread_cleanup_pop (1);
84 __attribute__((noinline
)) void
87 /* This is the old LinuxThreads pthread_cleanup_{push,pop}. */
88 struct _pthread_cleanup_buffer b
;
89 _pthread_cleanup_push (&b
, clh
, (void *) 2l);
93 _pthread_cleanup_pop (&b
, 1);
97 static __attribute__((noinline
)) void
100 pthread_cleanup_push (clh
, (void *) 3l);
104 pthread_cleanup_pop (1);
138 puts ("pipe failed");
142 if (pthread_barrier_init (&b2
, NULL
, 2) != 0)
144 puts ("b2 init failed");
157 for (i
= 0; i
< 4; ++i
)
161 printf ("test %ld\n", i
);
164 if (pthread_create (&th
, NULL
, tf
, (void *) i
) != 0)
166 puts ("create failed");
170 int e
= pthread_barrier_wait (&b2
);
171 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
173 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
180 if ((e
= pthread_join (th
, &r
)) != 0)
182 printf ("join failed: %d\n", e
);
186 if (r
!= PTHREAD_CANCELED
)
188 puts ("thread not canceled");
192 if (global
!= expect
[i
])
194 printf ("global = %d, expected %d\n", global
, expect
[i
]);
202 #define TEST_FUNCTION do_test ()
203 #include "../test-skeleton.c"