timer_gettime.c 2.3 KB

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