libc-cancellation.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <errno.h>
  16. #include <rpc/rpc.h>
  17. #include "pthread.h"
  18. #include "internals.h"
  19. #include "spinlock.h"
  20. #include "restart.h"
  21. #include <bits/libc-lock.h>
  22. #if !defined NOT_IN_libc
  23. # ifndef SHARED
  24. weak_extern (__pthread_do_exit)
  25. # endif
  26. /* The next two functions are similar to pthread_setcanceltype() but
  27. more specialized for the use in the cancelable functions like write().
  28. They do not need to check parameters etc. */
  29. int
  30. attribute_hidden
  31. __libc_enable_asynccancel (void)
  32. {
  33. pthread_descr self = thread_self();
  34. int oldtype = LIBC_THREAD_GETMEM(self, p_canceltype);
  35. LIBC_THREAD_SETMEM(self, p_canceltype, PTHREAD_CANCEL_ASYNCHRONOUS);
  36. if (__builtin_expect (LIBC_THREAD_GETMEM(self, p_canceled), 0) &&
  37. LIBC_THREAD_GETMEM(self, p_cancelstate) == PTHREAD_CANCEL_ENABLE)
  38. __libc_maybe_call2 (pthread_do_exit,
  39. (PTHREAD_CANCELED, CURRENT_STACK_FRAME), 0);
  40. return oldtype;
  41. }
  42. strong_alias (__libc_enable_asynccancel, __librt_enable_asynccancel)
  43. void
  44. internal_function attribute_hidden
  45. __libc_disable_asynccancel (int oldtype)
  46. {
  47. pthread_descr self = thread_self();
  48. LIBC_THREAD_SETMEM(self, p_canceltype, oldtype);
  49. }
  50. strong_alias (__libc_disable_asynccancel, __librt_disable_asynccancel)
  51. #endif