timer_settime.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 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_settime
  22. # ifndef __ASSUME_POSIX_TIMERS
  23. static int compat_timer_settime (timer_t timerid, int flags,
  24. const struct itimerspec *value,
  25. struct itimerspec *ovalue);
  26. # define timer_settime static compat_timer_settime
  27. # include <nptl/sysdeps/pthread/timer_settime.c>
  28. # undef timer_settime
  29. # endif
  30. # ifdef timer_settime_alias
  31. # define timer_settime timer_settime_alias
  32. # endif
  33. int
  34. timer_settime (
  35. timer_t timerid,
  36. int flags,
  37. const struct itimerspec *value,
  38. struct itimerspec *ovalue)
  39. {
  40. # undef timer_settime
  41. # ifndef __ASSUME_POSIX_TIMERS
  42. if (__no_posix_timers >= 0)
  43. # endif
  44. {
  45. struct timer *kt = (struct timer *) timerid;
  46. /* Delete the kernel timer object. */
  47. int res = INLINE_SYSCALL (timer_settime, 4, kt->ktimerid, flags,
  48. value, ovalue);
  49. # ifndef __ASSUME_POSIX_TIMERS
  50. if (res != -1 || errno != ENOSYS)
  51. {
  52. /* We know the syscall support is available. */
  53. __no_posix_timers = 1;
  54. # endif
  55. return res;
  56. # ifndef __ASSUME_POSIX_TIMERS
  57. }
  58. # endif
  59. # ifndef __ASSUME_POSIX_TIMERS
  60. __no_posix_timers = -1;
  61. # endif
  62. }
  63. # ifndef __ASSUME_POSIX_TIMERS
  64. return compat_timer_settime (timerid, flags, value, ovalue);
  65. # endif
  66. }
  67. #else
  68. # ifdef timer_settime_alias
  69. # define timer_settime timer_settime_alias
  70. # endif
  71. /* The new system calls are not available. Use the userlevel
  72. implementation. */
  73. # include <nptl/sysdeps/pthread/timer_settime.c>
  74. #endif