tst-tls3mod.c 2.1 KB

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