tst-tls3mod.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. static pthread_barrier_t* b = NULL;
  27. #define TOTAL_SIGS 1000
  28. static int* nsigs = NULL;
  29. static sem_t* s = NULL;
  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. setup_tf (pthread_barrier_t* t_b, int* t_nsigs, sem_t* t_s)
  49. {
  50. b = t_b;
  51. nsigs = t_nsigs;
  52. s = t_s;
  53. }
  54. void *
  55. tf (void *arg)
  56. {
  57. if (!b || !s || !nsigs)
  58. {
  59. puts ("need to call setup_tf first");
  60. exit (1);
  61. }
  62. if ((uintptr_t) pthread_self () & (TCB_ALIGNMENT - 1))
  63. {
  64. puts ("thread's struct pthread not aligned enough");
  65. exit (1);
  66. }
  67. if (fp != NULL)
  68. {
  69. printf("fp=%p\n", (void *)&fp);
  70. puts ("fp not initially NULL");
  71. exit (1);
  72. }
  73. fp = arg;
  74. pthread_barrier_wait (b);
  75. pthread_barrier_wait (b);
  76. if (*nsigs != TOTAL_SIGS)
  77. {
  78. puts ("barrier_wait prematurely returns");
  79. exit (1);
  80. }
  81. return NULL;
  82. }
  83. #endif