]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re-core/uclibc/lib/contrib/uclibc/test/nptl/tst-tls3mod.c
Update
[l4.git] / l4 / pkg / l4re-core / uclibc / lib / contrib / uclibc / test / nptl / tst-tls3mod.c
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.
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
16    License along with the GNU C Library; if not, see
17    <http://www.gnu.org/licenses/>.  */
18
19 #include <pthread.h>
20 #include <semaphore.h>
21 #include <signal.h>
22 #include <stdint.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <unistd.h>
26 #include <pthreaddef.h>
27 #include <tls.h>
28
29 #if HAVE___THREAD
30
31 static pthread_barrier_t* b = NULL;
32
33 #define TOTAL_SIGS 1000
34 static int* nsigs = NULL;
35
36 static sem_t* s = NULL;
37
38 static __thread void (*fp) (void);
39
40
41 #define THE_SIG SIGUSR1
42 void
43 handler (int sig)
44 {
45   if (sig != THE_SIG)
46     {
47       write (STDOUT_FILENO, "wrong signal\n", 13);
48       _exit (1);
49     }
50
51   fp ();
52
53   if (sem_post (s) != 0)
54     {
55       write (STDOUT_FILENO, "sem_post failed\n", 16);
56       _exit (1);
57     }
58 }
59
60 void
61 setup_tf (pthread_barrier_t* t_b, int* t_nsigs, sem_t* t_s)
62 {
63   b = t_b;
64   nsigs = t_nsigs;
65   s = t_s;
66 }
67
68 void *
69 tf (void *arg)
70 {
71   if (!b || !s || !nsigs)
72     {
73       puts ("need to call setup_tf first");
74       exit (1);
75     }
76
77   if ((uintptr_t) pthread_self () & (TCB_ALIGNMENT - 1))
78     {
79       puts ("thread's struct pthread not aligned enough");
80       exit (1);
81     }
82
83   if (fp != NULL)
84     {
85       printf("fp=%p\n", (void *)&fp);
86       puts ("fp not initially NULL");
87       exit (1);
88     }
89
90   fp = arg;
91
92   pthread_barrier_wait (b);
93
94   pthread_barrier_wait (b);
95
96   if (*nsigs != TOTAL_SIGS)
97     {
98       puts ("barrier_wait prematurely returns");
99       exit (1);
100     }
101
102   return NULL;
103 }
104
105 #endif