Back to index

glibc  2.9
aio_misc.h
Go to the documentation of this file.
00001 /* Copyright (C) 2004, 2006 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Jakub Jelinek <jakub@redhat.com>, 2004.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public License as
00007    published by the Free Software Foundation; either version 2.1 of the
00008    License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; see the file COPYING.LIB.  If not,
00017    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, USA.  */
00019 
00020 #ifndef _AIO_MISC_H
00021 # include_next <aio_misc.h>
00022 # include <limits.h>
00023 # include <pthread.h>
00024 # include <signal.h>
00025 # include <sysdep.h>
00026 
00027 # define aio_start_notify_thread __aio_start_notify_thread
00028 # define aio_create_helper_thread __aio_create_helper_thread
00029 
00030 extern inline void
00031 __aio_start_notify_thread (void)
00032 {
00033   sigset_t ss;
00034   sigemptyset (&ss);
00035   INTERNAL_SYSCALL_DECL (err);
00036   INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_SETMASK, &ss, NULL, _NSIG / 8);
00037 }
00038 
00039 extern inline int
00040 __aio_create_helper_thread (pthread_t *threadp, void *(*tf) (void *),
00041                          void *arg)
00042 {
00043   pthread_attr_t attr;
00044 
00045   /* Make sure the thread is created detached.  */
00046   pthread_attr_init (&attr);
00047   pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
00048 
00049   /* The helper thread needs only very little resources.  */
00050   (void) pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN);
00051 
00052   /* Block all signals in the helper thread.  To do this thoroughly we
00053      temporarily have to block all signals here.  */
00054   sigset_t ss;
00055   sigset_t oss;
00056   sigfillset (&ss);
00057   INTERNAL_SYSCALL_DECL (err);
00058   INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_SETMASK, &ss, &oss, _NSIG / 8);
00059 
00060   int ret = pthread_create (threadp, &attr, tf, arg);
00061 
00062   /* Restore the signal mask.  */
00063   INTERNAL_SYSCALL (rt_sigprocmask, err, 4, SIG_SETMASK, &oss, NULL,
00064                   _NSIG / 8);
00065 
00066   (void) pthread_attr_destroy (&attr);
00067   return ret;
00068 }
00069 #endif