Back to index

glibc  2.9
tst-tls3mod.c
Go to the documentation of this file.
00001 /* Copyright (C) 2003 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <pthread.h>
00021 #include <semaphore.h>
00022 #include <signal.h>
00023 #include <stdint.h>
00024 #include <stdio.h>
00025 #include <stdlib.h>
00026 #include <unistd.h>
00027 #include <pthreaddef.h>
00028 
00029 #if HAVE___THREAD
00030 
00031 extern pthread_barrier_t b;
00032 
00033 #define TOTAL_SIGS 1000
00034 extern int nsigs;
00035 
00036 extern sem_t s;
00037 
00038 
00039 static __thread void (*fp) (void);
00040 
00041 
00042 #define THE_SIG SIGUSR1
00043 void
00044 handler (int sig)
00045 {
00046   if (sig != THE_SIG)
00047     {
00048       write (STDOUT_FILENO, "wrong signal\n", 13);
00049       _exit (1);
00050     }
00051 
00052   fp ();
00053 
00054   if (sem_post (&s) != 0)
00055     {
00056       write (STDOUT_FILENO, "sem_post failed\n", 16);
00057       _exit (1);
00058     }
00059 }
00060 
00061 
00062 void *
00063 tf (void *arg)
00064 {
00065   if ((uintptr_t) pthread_self () & (TCB_ALIGNMENT - 1))
00066     {
00067       puts ("thread's struct pthread not aligned enough");
00068       exit (1);
00069     }
00070 
00071   if (fp != NULL)
00072     {
00073       puts ("fp not initially NULL");
00074       exit (1);
00075     }
00076 
00077   fp = arg;
00078 
00079   pthread_barrier_wait (&b);
00080 
00081   pthread_barrier_wait (&b);
00082 
00083   if (nsigs != TOTAL_SIGS)
00084     {
00085       puts ("barrier_wait prematurely returns");
00086       exit (1);
00087     }
00088 
00089   return NULL;
00090 }
00091 
00092 #endif