Back to index

glibc  2.9
gai_misc.h
Go to the documentation of this file.
00001 /* Copyright (C) 2006 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 /* We define a special synchronization primitive for AIO.  POSIX
00020    conditional variables would be ideal but the pthread_cond_*wait
00021    operations do not return on EINTR.  This is a requirement for
00022    correct aio_suspend and lio_listio implementations.  */
00023 
00024 #include <assert.h>
00025 #include <signal.h>
00026 
00027 #undef DONT_NEED_GAI_MISC_COND
00028 
00029 #define gai_start_notify_thread __gai_start_notify_thread
00030 #define gai_create_helper_thread __gai_create_helper_thread
00031 
00032 extern inline void
00033 __gai_start_notify_thread (void)
00034 {
00035   sigset_t ss;
00036   sigemptyset (&ss);
00037   sigprocmask (SIG_SETMASK, &ss, NULL);
00038 }
00039 
00040 extern inline int
00041 __gai_create_helper_thread (pthread_t *threadp, void *(*tf) (void *),
00042                          void *arg)
00043 {
00044   pthread_attr_t attr;
00045 
00046   /* Make sure the thread is created detached.  */
00047   pthread_attr_init (&attr);
00048   pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
00049 
00050   /* The helper thread needs only very little resources.  */
00051   (void) pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN);
00052 
00053   /* Block all signals in the helper thread.  To do this thoroughly we
00054      temporarily have to block all signals here.  */
00055   sigset_t ss;
00056   sigset_t oss;
00057   sigfillset (&ss);
00058   sigprocmask (SIG_SETMASK, &ss, &oss);
00059 
00060   int ret = pthread_create (threadp, &attr, tf, arg);
00061 
00062   /* Restore the signal mask.  */
00063   sigprocmask (SIG_SETMASK, &oss, NULL);
00064 
00065   (void) pthread_attr_destroy (&attr);
00066   return ret;
00067 }
00068 
00069 #include_next <gai_misc.h>