pt-testcancel.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* Add an explicit cancelation point.
  2. Copyright (C) 2002-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  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. <https://www.gnu.org/licenses/>. */
  15. #include <pthread.h>
  16. #include <pt-internal.h>
  17. #include <pthreadP.h>
  18. #include <shlib-compat.h>
  19. void
  20. __pthread_testcancel (void)
  21. {
  22. struct __pthread *p = _pthread_self ();
  23. int cancelled;
  24. __pthread_mutex_lock (&p->cancel_lock);
  25. cancelled = (p->cancel_state == PTHREAD_CANCEL_ENABLE) && p->cancel_pending;
  26. __pthread_mutex_unlock (&p->cancel_lock);
  27. if (cancelled)
  28. __pthread_exit (PTHREAD_CANCELED);
  29. }
  30. libc_hidden_def (__pthread_testcancel)
  31. versioned_symbol (libc, __pthread_testcancel, pthread_testcancel, GLIBC_2_43);
  32. #if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_12, GLIBC_2_43)
  33. compat_symbol (libpthread, __pthread_testcancel, pthread_testcancel, GLIBC_2_12);
  34. #endif