aio_misc.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* Copyright (C) 2004-2019 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Jakub Jelinek <jakub@redhat.com>, 2004.
  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 License as
  6. published by the Free Software Foundation; either version 2.1 of the
  7. 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; see the file COPYING.LIB. If
  14. not, see <http://www.gnu.org/licenses/>. */
  15. #ifndef _AIO_MISC_H
  16. # include_next <aio_misc.h>
  17. # include <limits.h>
  18. # include <pthread.h>
  19. # include <signal.h>
  20. # include <sysdep.h>
  21. # define aio_start_notify_thread __aio_start_notify_thread
  22. # define aio_create_helper_thread __aio_create_helper_thread
  23. extern inline void
  24. __aio_start_notify_thread (void)
  25. {
  26. sigset_t ss;
  27. sigemptyset (&ss);
  28. INTERNAL_SYSCALL_DECL (err);
  29. INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_SETMASK, &ss, NULL, _NSIG / 8);
  30. }
  31. extern inline int
  32. __aio_create_helper_thread (pthread_t *threadp, void *(*tf) (void *),
  33. void *arg)
  34. {
  35. pthread_attr_t attr;
  36. /* Make sure the thread is created detached. */
  37. pthread_attr_init (&attr);
  38. pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
  39. /* The helper thread needs only very little resources. */
  40. (void) pthread_attr_setstacksize (&attr, __pthread_get_minstack (&attr));
  41. /* Block all signals in the helper thread. To do this thoroughly we
  42. temporarily have to block all signals here. */
  43. sigset_t ss;
  44. sigset_t oss;
  45. sigfillset (&ss);
  46. INTERNAL_SYSCALL_DECL (err);
  47. INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_SETMASK, &ss, &oss, _NSIG / 8);
  48. int ret = pthread_create (threadp, &attr, tf, arg);
  49. /* Restore the signal mask. */
  50. INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_SETMASK, &oss, NULL,
  51. _NSIG / 8);
  52. (void) pthread_attr_destroy (&attr);
  53. return ret;
  54. }
  55. #endif