Blame sysdeps/unix/sysv/linux/aio_misc.h

Packit 6c4009
/* Copyright (C) 2004-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Contributed by Jakub Jelinek <jakub@redhat.com>, 2004.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public License as
Packit 6c4009
   published by the Free Software Foundation; either version 2.1 of the
Packit 6c4009
   License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; see the file COPYING.LIB.  If
Packit 6c4009
   not, see <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#ifndef _AIO_MISC_H
Packit 6c4009
# include_next <aio_misc.h>
Packit 6c4009
# include <limits.h>
Packit 6c4009
# include <pthread.h>
Packit 6c4009
# include <signal.h>
Packit 6c4009
# include <sysdep.h>
Packit 6c4009
Packit 6c4009
# define aio_start_notify_thread __aio_start_notify_thread
Packit 6c4009
# define aio_create_helper_thread __aio_create_helper_thread
Packit 6c4009
Packit 6c4009
extern inline void
Packit 6c4009
__aio_start_notify_thread (void)
Packit 6c4009
{
Packit 6c4009
  sigset_t ss;
Packit 6c4009
  sigemptyset (&ss);
Packit 6c4009
  INTERNAL_SYSCALL_DECL (err);
Packit 6c4009
  INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_SETMASK, &ss, NULL, _NSIG / 8);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
extern inline int
Packit 6c4009
__aio_create_helper_thread (pthread_t *threadp, void *(*tf) (void *),
Packit 6c4009
			    void *arg)
Packit 6c4009
{
Packit 6c4009
  pthread_attr_t attr;
Packit 6c4009
Packit 6c4009
  /* Make sure the thread is created detached.  */
Packit 6c4009
  pthread_attr_init (&attr);
Packit 6c4009
  pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
Packit 6c4009
Packit 6c4009
  /* The helper thread needs only very little resources.  */
Packit 6c4009
  (void) pthread_attr_setstacksize (&attr, __pthread_get_minstack (&attr));
Packit 6c4009
Packit 6c4009
  /* Block all signals in the helper thread.  To do this thoroughly we
Packit 6c4009
     temporarily have to block all signals here.  */
Packit 6c4009
  sigset_t ss;
Packit 6c4009
  sigset_t oss;
Packit 6c4009
  sigfillset (&ss);
Packit 6c4009
  INTERNAL_SYSCALL_DECL (err);
Packit 6c4009
  INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_SETMASK, &ss, &oss, _NSIG / 8);
Packit 6c4009
Packit 6c4009
  int ret = pthread_create (threadp, &attr, tf, arg);
Packit 6c4009
Packit 6c4009
  /* Restore the signal mask.  */
Packit 6c4009
  INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_SETMASK, &oss, NULL,
Packit 6c4009
		    _NSIG / 8);
Packit 6c4009
Packit 6c4009
  (void) pthread_attr_destroy (&attr);
Packit 6c4009
  return ret;
Packit 6c4009
}
Packit 6c4009
#endif