tst-tls3mod.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <pthread.h>
  16. #include <semaphore.h>
  17. #include <signal.h>
  18. #include <stdint.h>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <unistd.h>
  22. #include <pthreaddef.h>
  23. #include <tls.h>
  24. #if HAVE___THREAD
  25. static pthread_barrier_t* b = NULL;
  26. #define TOTAL_SIGS 1000
  27. static int* nsigs = NULL;
  28. static sem_t* s = NULL;
  29. static __thread void (*fp) (void);
  30. #define THE_SIG SIGUSR1
  31. void
  32. handler (int sig)
  33. {
  34. if (sig != THE_SIG)
  35. {
  36. write (STDOUT_FILENO, "wrong signal\n", 13);
  37. _exit (1);
  38. }
  39. fp ();
  40. if (sem_post (s) != 0)
  41. {
  42. write (STDOUT_FILENO, "sem_post failed\n", 16);
  43. _exit (1);
  44. }
  45. }
  46. void
  47. setup_tf (pthread_barrier_t* t_b, int* t_nsigs, sem_t* t_s)
  48. {
  49. b = t_b;
  50. nsigs = t_nsigs;
  51. s = t_s;
  52. }
  53. void *
  54. tf (void *arg)
  55. {
  56. if (!b || !s || !nsigs)
  57. {
  58. puts ("need to call setup_tf first");
  59. exit (1);
  60. }
  61. if ((uintptr_t) pthread_self () & (TCB_ALIGNMENT - 1))
  62. {
  63. puts ("thread's struct pthread not aligned enough");
  64. exit (1);
  65. }
  66. if (fp != NULL)
  67. {
  68. printf("fp=%p\n", (void *)&fp);
  69. puts ("fp not initially NULL");
  70. exit (1);
  71. }
  72. fp = arg;
  73. pthread_barrier_wait (b);
  74. pthread_barrier_wait (b);
  75. if (*nsigs != TOTAL_SIGS)
  76. {
  77. puts ("barrier_wait prematurely returns");
  78. exit (1);
  79. }
  80. return NULL;
  81. }
  82. #endif