libc-cancellation.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* Copyright (C) 2002 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Jakub Jelinek <jakub@redhat.com>, 2002.
  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
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the 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; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #include <errno.h>
  17. #include <rpc/rpc.h>
  18. #include "pthread.h"
  19. #include "internals.h"
  20. #include "spinlock.h"
  21. #include "restart.h"
  22. #include <bits/libc-lock.h>
  23. #if !defined NOT_IN_libc
  24. # ifndef SHARED
  25. weak_extern (__pthread_do_exit)
  26. # endif
  27. int __libc_multiple_threads attribute_hidden __attribute__((nocommon));
  28. strong_alias (__libc_multiple_threads, __librt_multiple_threads)
  29. /* The next two functions are similar to pthread_setcanceltype() but
  30. more specialized for the use in the cancelable functions like write().
  31. They do not need to check parameters etc. */
  32. int
  33. attribute_hidden
  34. __libc_enable_asynccancel (void)
  35. {
  36. pthread_descr self = thread_self();
  37. int oldtype = LIBC_THREAD_GETMEM(self, p_canceltype);
  38. LIBC_THREAD_SETMEM(self, p_canceltype, PTHREAD_CANCEL_ASYNCHRONOUS);
  39. if (__builtin_expect (LIBC_THREAD_GETMEM(self, p_canceled), 0) &&
  40. LIBC_THREAD_GETMEM(self, p_cancelstate) == PTHREAD_CANCEL_ENABLE)
  41. __libc_maybe_call2 (pthread_do_exit,
  42. (PTHREAD_CANCELED, CURRENT_STACK_FRAME), 0);
  43. return oldtype;
  44. }
  45. strong_alias (__libc_enable_asynccancel, __librt_enable_asynccancel)
  46. void
  47. internal_function attribute_hidden
  48. __libc_disable_asynccancel (int oldtype)
  49. {
  50. pthread_descr self = thread_self();
  51. LIBC_THREAD_SETMEM(self, p_canceltype, oldtype);
  52. }
  53. strong_alias (__libc_disable_asynccancel, __librt_disable_asynccancel)
  54. #endif