* sysdeps/unix/sysv/linux/m68k/semtimedop.S: New file.
[glibc/pb-stable.git] / nptl / tst-tls3.c
blob4e7ca8e2313c2c9e2ac22342679c1fe6e03bfc9b
1 /* Copyright (C) 2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@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
18 02111-1307 USA. */
20 #include <dlfcn.h>
21 #include <errno.h>
22 #include <pthread.h>
23 #include <signal.h>
24 #include <semaphore.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <unistd.h>
30 #define THE_SIG SIGUSR1
33 #define N 10
34 static pthread_t th[N];
37 #define CB(n) \
38 static void \
39 cb##n (void) \
40 { \
41 if (th[n] != pthread_self ()) \
42 { \
43 write (STDOUT_FILENO, "wrong callback\n", 15); \
44 _exit (1); \
45 } \
47 CB (0)
48 CB (1)
49 CB (2)
50 CB (3)
51 CB (4)
52 CB (5)
53 CB (6)
54 CB (7)
55 CB (8)
56 CB (9)
57 static void (*cbs[]) (void) =
59 cb0, cb1, cb2, cb3, cb4, cb5, cb6, cb7, cb8, cb9
63 sem_t s;
66 pthread_barrier_t b;
68 #define TOTAL_SIGS 1000
69 int nsigs;
72 int
73 do_test (void)
75 #if !HAVE___THREAD
77 puts ("No __thread support in compiler, test skipped.");
79 return 0;
80 #else
82 if (pthread_barrier_init (&b, NULL, N + 1) != 0)
84 puts ("barrier_init failed");
85 exit (1);
88 if (sem_init (&s, 0, 0) != 0)
90 puts ("sem_init failed");
91 exit (1);
94 void *h = dlopen ("tst-tls3mod.so", RTLD_LAZY);
95 if (h == NULL)
97 puts ("dlopen failed");
98 exit (1);
101 void *(*tf) (void *) = dlsym (h, "tf");
102 if (tf == NULL)
104 puts ("dlsym for tf failed");
105 exit (1);
108 struct sigaction sa;
109 sa.sa_handler = dlsym (h, "handler");
110 if (sa.sa_handler == NULL)
112 puts ("dlsym for handler failed");
113 exit (1);
115 sigemptyset (&sa.sa_mask);
116 sa.sa_flags = 0;
117 if (sigaction (THE_SIG, &sa, NULL) != 0)
119 puts ("sigaction failed");
120 exit (1);
123 int r;
124 for (r = 0; r < 10; ++r)
126 int i;
127 for (i = 0; i < N; ++i)
128 if (pthread_create (&th[i], NULL, tf, cbs[i]) != 0)
130 puts ("pthread_create failed");
131 exit (1);
134 nsigs = 0;
136 pthread_barrier_wait (&b);
138 sigset_t ss;
139 sigemptyset (&ss);
140 sigaddset (&ss, THE_SIG);
141 if (pthread_sigmask (SIG_BLOCK, &ss, NULL) != 0)
143 puts ("pthread_sigmask failed");
144 exit (1);
147 /* Start sending signals. */
148 for (i = 0; i < TOTAL_SIGS; ++i)
150 if (kill (getpid (), THE_SIG) != 0)
152 puts ("kill failed");
153 exit (1);
156 if (TEMP_FAILURE_RETRY (sem_wait (&s)) != 0)
158 puts ("sem_wait failed");
159 exit (1);
162 ++nsigs;
165 pthread_barrier_wait (&b);
167 if (pthread_sigmask (SIG_UNBLOCK, &ss, NULL) != 0)
169 puts ("pthread_sigmask failed");
170 exit (1);
173 for (i = 0; i < N; ++i)
174 if (pthread_join (th[i], NULL) != 0)
176 puts ("join failed");
177 exit (1);
181 return 0;
182 #endif
186 #define TIMEOUT 5
187 #define TEST_FUNCTION do_test ()
188 #include "../test-skeleton.c"