Back to index

glibc  2.9
timer_gettime.c
Go to the documentation of this file.
00001 /* Copyright (C) 2003 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public License as
00007    published by the Free Software Foundation; either version 2.1 of the
00008    License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; see the file COPYING.LIB.  If not,
00017    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, USA.  */
00019 
00020 #include <errno.h>
00021 #include <stdlib.h>
00022 #include <time.h>
00023 #include <sysdep.h>
00024 #include <kernel-features.h>
00025 #include "kernel-posix-timers.h"
00026 
00027 
00028 #ifdef __NR_timer_gettime
00029 # ifndef __ASSUME_POSIX_TIMERS
00030 static int compat_timer_gettime (timer_t timerid, struct itimerspec *value);
00031 #  define timer_gettime static compat_timer_gettime
00032 #  include <nptl/sysdeps/pthread/timer_gettime.c>
00033 #  undef timer_gettime
00034 # endif
00035 
00036 # ifdef timer_gettime_alias
00037 #  define timer_gettime timer_gettime_alias
00038 # endif
00039 
00040 
00041 int
00042 timer_gettime (timerid, value)
00043      timer_t timerid;
00044      struct itimerspec *value;
00045 {
00046 # undef timer_gettime
00047 # ifndef __ASSUME_POSIX_TIMERS
00048   if (__no_posix_timers >= 0)
00049 # endif
00050     {
00051       struct timer *kt = (struct timer *) timerid;
00052 
00053       /* Delete the kernel timer object.  */
00054       int res = INLINE_SYSCALL (timer_gettime, 2, kt->ktimerid, value);
00055 
00056 # ifndef __ASSUME_POSIX_TIMERS
00057       if (res != -1 || errno != ENOSYS)
00058        {
00059          /* We know the syscall support is available.  */
00060          __no_posix_timers = 1;
00061 # endif
00062          return res;
00063 # ifndef __ASSUME_POSIX_TIMERS
00064        }
00065 # endif
00066 
00067 # ifndef __ASSUME_POSIX_TIMERS
00068       __no_posix_timers = -1;
00069 # endif
00070     }
00071 
00072 # ifndef __ASSUME_POSIX_TIMERS
00073   return compat_timer_gettime (timerid, value);
00074 # endif
00075 }
00076 #else
00077 # ifdef timer_gettime_alias
00078 #  define timer_gettime timer_gettime_alias
00079 # endif
00080 /* The new system calls are not available.  Use the userlevel
00081    implementation.  */
00082 # include <nptl/sysdeps/pthread/timer_gettime.c>
00083 #endif