Back to index

glibc  2.9
timer_delete.c
Go to the documentation of this file.
00001 /* Copyright (C) 2003, 2007 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_delete
00029 # ifndef __ASSUME_POSIX_TIMERS
00030 static int compat_timer_delete (timer_t timerid);
00031 #  define timer_delete static compat_timer_delete
00032 #  include <nptl/sysdeps/pthread/timer_delete.c>
00033 #  undef timer_delete
00034 # endif
00035 
00036 # ifdef timer_delete_alias
00037 #  define timer_delete timer_delete_alias
00038 # endif
00039 
00040 
00041 int
00042 timer_delete (timerid)
00043      timer_t timerid;
00044 {
00045 # undef timer_delete
00046 # ifndef __ASSUME_POSIX_TIMERS
00047   if (__no_posix_timers >= 0)
00048 # endif
00049     {
00050       struct timer *kt = (struct timer *) timerid;
00051 
00052       /* Delete the kernel timer object.  */
00053       int res = INLINE_SYSCALL (timer_delete, 1, kt->ktimerid);
00054 
00055       if (res == 0)
00056        {
00057          if (kt->sigev_notify == SIGEV_THREAD)
00058            {
00059              /* Remove the timer from the list.  */
00060              pthread_mutex_lock (&__active_timer_sigev_thread_lock);
00061              if (__active_timer_sigev_thread == kt)
00062               __active_timer_sigev_thread = kt->next;
00063              else
00064               {
00065                 struct timer *prevp = __active_timer_sigev_thread;
00066                 while (prevp->next != NULL)
00067                   if (prevp->next == kt)
00068                     {
00069                      prevp->next = kt->next;
00070                      break;
00071                     }
00072                   else
00073                     prevp = prevp->next;
00074               }
00075              pthread_mutex_unlock (&__active_timer_sigev_thread_lock);
00076            }
00077 
00078 # ifndef __ASSUME_POSIX_TIMERS
00079          /* We know the syscall support is available.  */
00080          __no_posix_timers = 1;
00081 # endif
00082 
00083          /* Free the memory.  */
00084          (void) free (kt);
00085 
00086          return 0;
00087        }
00088 
00089       /* The kernel timer is not known or something else bad happened.
00090         Return the error.  */
00091 # ifndef __ASSUME_POSIX_TIMERS
00092       if (errno != ENOSYS)
00093        {
00094          __no_posix_timers = 1;
00095 # endif
00096          return -1;
00097 # ifndef __ASSUME_POSIX_TIMERS
00098        }
00099 
00100       __no_posix_timers = -1;
00101 # endif
00102     }
00103 
00104 # ifndef __ASSUME_POSIX_TIMERS
00105   return compat_timer_delete (timerid);
00106 # endif
00107 }
00108 #else
00109 # ifdef timer_delete_alias
00110 #  define timer_delete timer_delete_alias
00111 # endif
00112 /* The new system calls are not available.  Use the userlevel
00113    implementation.  */
00114 # include <nptl/sysdeps/pthread/timer_delete.c>
00115 #endif