timer_delete.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* Copyright (C) 2003, 2007 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 License as
  6. published by the Free Software Foundation; either version 2.1 of the
  7. 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; see the file COPYING.LIB. If
  14. not, see <http://www.gnu.org/licenses/>. */
  15. #include <errno.h>
  16. #include <stdlib.h>
  17. #include <time.h>
  18. #include <sysdep.h>
  19. #include <bits/kernel-features.h>
  20. #include "kernel-posix-timers.h"
  21. #ifdef __NR_timer_delete
  22. # ifndef __ASSUME_POSIX_TIMERS
  23. static int compat_timer_delete (timer_t timerid);
  24. # define timer_delete static compat_timer_delete
  25. # include <nptl/sysdeps/pthread/timer_delete.c>
  26. # undef timer_delete
  27. # endif
  28. # ifdef timer_delete_alias
  29. # define timer_delete timer_delete_alias
  30. # endif
  31. int
  32. timer_delete (
  33. timer_t timerid)
  34. {
  35. # undef timer_delete
  36. # ifndef __ASSUME_POSIX_TIMERS
  37. if (__no_posix_timers >= 0)
  38. # endif
  39. {
  40. struct timer *kt = (struct timer *) timerid;
  41. /* Delete the kernel timer object. */
  42. int res = INLINE_SYSCALL (timer_delete, 1, kt->ktimerid);
  43. if (res == 0)
  44. {
  45. if (kt->sigev_notify == SIGEV_THREAD)
  46. {
  47. /* Remove the timer from the list. */
  48. pthread_mutex_lock (&__active_timer_sigev_thread_lock);
  49. if (__active_timer_sigev_thread == kt)
  50. __active_timer_sigev_thread = kt->next;
  51. else
  52. {
  53. struct timer *prevp = __active_timer_sigev_thread;
  54. while (prevp->next != NULL)
  55. if (prevp->next == kt)
  56. {
  57. prevp->next = kt->next;
  58. break;
  59. }
  60. else
  61. prevp = prevp->next;
  62. }
  63. pthread_mutex_unlock (&__active_timer_sigev_thread_lock);
  64. }
  65. # ifndef __ASSUME_POSIX_TIMERS
  66. /* We know the syscall support is available. */
  67. __no_posix_timers = 1;
  68. # endif
  69. /* Free the memory. */
  70. (void) free (kt);
  71. return 0;
  72. }
  73. /* The kernel timer is not known or something else bad happened.
  74. Return the error. */
  75. # ifndef __ASSUME_POSIX_TIMERS
  76. if (errno != ENOSYS)
  77. {
  78. __no_posix_timers = 1;
  79. # endif
  80. return -1;
  81. # ifndef __ASSUME_POSIX_TIMERS
  82. }
  83. __no_posix_timers = -1;
  84. # endif
  85. }
  86. # ifndef __ASSUME_POSIX_TIMERS
  87. return compat_timer_delete (timerid);
  88. # endif
  89. }
  90. #else
  91. # ifdef timer_delete_alias
  92. # define timer_delete timer_delete_alias
  93. # endif
  94. /* The new system calls are not available. Use the userlevel
  95. implementation. */
  96. # include <nptl/sysdeps/pthread/timer_delete.c>
  97. #endif