libc-cancellation.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. /* The next two functions are similar to pthread_setcanceltype() but
  28. more specialized for the use in the cancelable functions like write().
  29. They do not need to check parameters etc. */
  30. int
  31. attribute_hidden
  32. __libc_enable_asynccancel (void)
  33. {
  34. pthread_descr self = thread_self();
  35. int oldtype = LIBC_THREAD_GETMEM(self, p_canceltype);
  36. LIBC_THREAD_SETMEM(self, p_canceltype, PTHREAD_CANCEL_ASYNCHRONOUS);
  37. if (__builtin_expect (LIBC_THREAD_GETMEM(self, p_canceled), 0) &&
  38. LIBC_THREAD_GETMEM(self, p_cancelstate) == PTHREAD_CANCEL_ENABLE)
  39. __libc_maybe_call2 (pthread_do_exit,
  40. (PTHREAD_CANCELED, CURRENT_STACK_FRAME), 0);
  41. return oldtype;
  42. }
  43. strong_alias (__libc_enable_asynccancel, __librt_enable_asynccancel)
  44. void
  45. internal_function attribute_hidden
  46. __libc_disable_asynccancel (int oldtype)
  47. {
  48. pthread_descr self = thread_self();
  49. LIBC_THREAD_SETMEM(self, p_canceltype, oldtype);
  50. }
  51. strong_alias (__libc_disable_asynccancel, __librt_disable_asynccancel)
  52. #endif