1 /* Copyright (C) 2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
25 /* LinuxThreads pthread_cleanup_{push,pop} helpers. */
26 extern void _pthread_cleanup_push (struct _pthread_cleanup_buffer
*__buffer
,
27 void (*__routine
) (void *),
29 extern void _pthread_cleanup_pop (struct _pthread_cleanup_buffer
*__buffer
,
33 static pthread_barrier_t b2
;
36 /* Defined in tst-cleanup4aux.c, never compiled with -fexceptions. */
37 extern void fn5 (void);
38 extern void fn7 (void);
39 extern void fn9 (void);
44 int val
= (long int) arg
;
46 printf ("clh (%d)\n", val
);
53 static __attribute__((noinline
)) void
56 int r
= pthread_barrier_wait (&b2
);
57 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
59 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
68 __attribute__((noinline
)) void
71 pthread_cleanup_push (clh
, (void *) 1l);
75 pthread_cleanup_pop (1);
79 __attribute__((noinline
)) void
82 /* This is the old LinuxThreads pthread_cleanup_{push,pop}. */
83 struct _pthread_cleanup_buffer b
;
84 _pthread_cleanup_push (&b
, clh
, (void *) 2l);
88 _pthread_cleanup_pop (&b
, 1);
92 static __attribute__((noinline
)) void
95 pthread_cleanup_push (clh
, (void *) 3l);
99 pthread_cleanup_pop (1);
133 puts ("pipe failed");
137 if (pthread_barrier_init (&b2
, NULL
, 2) != 0)
139 puts ("b2 init failed");
152 for (i
= 0; i
< 4; ++i
)
156 printf ("test %ld\n", i
);
159 if (pthread_create (&th
, NULL
, tf
, (void *) i
) != 0)
161 puts ("create failed");
165 int e
= pthread_barrier_wait (&b2
);
166 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
168 printf ("%s: barrier_wait failed\n", __FUNCTION__
);
175 if ((e
= pthread_join (th
, &r
)) != 0)
177 printf ("join failed: %d\n", e
);
181 if (r
!= PTHREAD_CANCELED
)
183 puts ("thread not canceled");
187 if (global
!= expect
[i
])
189 printf ("global = %d, expected %d\n", global
, expect
[i
]);
197 #define TEST_FUNCTION do_test ()
198 #include "../test-skeleton.c"