Back to index

glibc  2.9
libc-cancellation.c
Go to the documentation of this file.
00001 /* Copyright (C) 2002 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Jakub Jelinek <jakub@redhat.com>, 2002.
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
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the 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; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <errno.h>
00021 #include <rpc/rpc.h>
00022 #include "pthread.h"
00023 #include "internals.h"
00024 #include "spinlock.h"
00025 #include "restart.h"
00026 #include <bits/libc-lock.h>
00027 
00028 #if !defined NOT_IN_libc
00029 
00030 # ifndef SHARED
00031 weak_extern (__pthread_do_exit)
00032 # endif
00033 
00034 int __libc_multiple_threads attribute_hidden __attribute__((nocommon));
00035 strong_alias (__libc_multiple_threads, __librt_multiple_threads);
00036 
00037 /* The next two functions are similar to pthread_setcanceltype() but
00038    more specialized for the use in the cancelable functions like write().
00039    They do not need to check parameters etc.  */
00040 int
00041 attribute_hidden
00042 __libc_enable_asynccancel (void)
00043 {
00044   pthread_descr self = thread_self();
00045   int oldtype = LIBC_THREAD_GETMEM(self, p_canceltype);
00046   LIBC_THREAD_SETMEM(self, p_canceltype, PTHREAD_CANCEL_ASYNCHRONOUS);
00047   if (__builtin_expect (LIBC_THREAD_GETMEM(self, p_canceled), 0) &&
00048       LIBC_THREAD_GETMEM(self, p_cancelstate) == PTHREAD_CANCEL_ENABLE)
00049     __libc_maybe_call2 (pthread_do_exit,
00050                      (PTHREAD_CANCELED, CURRENT_STACK_FRAME), 0);
00051   return oldtype;
00052 }
00053 strong_alias (__libc_enable_asynccancel, __librt_enable_asynccancel)
00054 
00055 void
00056 internal_function attribute_hidden
00057 __libc_disable_asynccancel (int oldtype)
00058 {
00059   pthread_descr self = thread_self();
00060   LIBC_THREAD_SETMEM(self, p_canceltype, oldtype);
00061 }
00062 strong_alias (__libc_disable_asynccancel, __librt_disable_asynccancel)
00063 
00064 #endif