timer_delete.c 3.0 KB

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