tst-tls3mod.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. 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.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #include <pthread.h>
  17. #include <semaphore.h>
  18. #include <signal.h>
  19. #include <stdint.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <unistd.h>
  23. #include <pthreaddef.h>
  24. #include <tls.h>
  25. #if HAVE___THREAD
  26. extern pthread_barrier_t b;
  27. #define TOTAL_SIGS 1000
  28. extern int nsigs;
  29. extern sem_t s;
  30. static __thread void (*fp) (void);
  31. #define THE_SIG SIGUSR1
  32. void
  33. handler (int sig)
  34. {
  35. if (sig != THE_SIG)
  36. {
  37. write (STDOUT_FILENO, "wrong signal\n", 13);
  38. _exit (1);
  39. }
  40. fp ();
  41. if (sem_post (&s) != 0)
  42. {
  43. write (STDOUT_FILENO, "sem_post failed\n", 16);
  44. _exit (1);
  45. }
  46. }
  47. void *
  48. tf (void *arg)
  49. {
  50. if ((uintptr_t) pthread_self () & (TCB_ALIGNMENT - 1))
  51. {
  52. puts ("thread's struct pthread not aligned enough");
  53. exit (1);
  54. }
  55. if (fp != NULL)
  56. {
  57. printf("fp=%p\n", (void *)&fp);
  58. puts ("fp not initially NULL");
  59. exit (1);
  60. }
  61. fp = arg;
  62. pthread_barrier_wait (&b);
  63. pthread_barrier_wait (&b);
  64. if (nsigs != TOTAL_SIGS)
  65. {
  66. puts ("barrier_wait prematurely returns");
  67. exit (1);
  68. }
  69. return NULL;
  70. }
  71. #endif