Back to index

glibc  2.9
pthread_attr_init.c
Go to the documentation of this file.
00001 /* Copyright (C) 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
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
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the 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; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <assert.h>
00021 #include <errno.h>
00022 #include <string.h>
00023 #include <unistd.h>
00024 #include "pthreadP.h"
00025 
00026 #include <shlib-compat.h>
00027 
00028 
00029 struct pthread_attr *__attr_list;
00030 int __attr_list_lock = LLL_LOCK_INITIALIZER;
00031 
00032 
00033 int
00034 __pthread_attr_init_2_1 (attr)
00035      pthread_attr_t *attr;
00036 {
00037   struct pthread_attr *iattr;
00038 
00039   /* Many elements are initialized to zero so let us do it all at
00040      once.  This also takes care of clearing the bytes which are not
00041      internally used.  */
00042   memset (attr, '\0', __SIZEOF_PTHREAD_ATTR_T);
00043 
00044   assert (sizeof (*attr) >= sizeof (struct pthread_attr));
00045   iattr = (struct pthread_attr *) attr;
00046 
00047   /* Default guard size specified by the standard.  */
00048   iattr->guardsize = __getpagesize ();
00049 
00050   return 0;
00051 }
00052 versioned_symbol (libpthread, __pthread_attr_init_2_1, pthread_attr_init,
00053                 GLIBC_2_1);
00054 
00055 
00056 #if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_1)
00057 int
00058 __pthread_attr_init_2_0 (attr)
00059      pthread_attr_t *attr;
00060 {
00061   /* This code is specific to the old LinuxThread code which has a too
00062      small pthread_attr_t definition.  The struct looked like
00063      this:  */
00064   struct old_attr
00065   {
00066     int detachstate;
00067     int schedpolicy;
00068     struct sched_param schedparam;
00069     int inheritsched;
00070     int scope;
00071   };
00072   struct pthread_attr *iattr;
00073 
00074   /* Many elements are initialized to zero so let us do it all at
00075      once.  This also takes care of clearing the bytes which are not
00076      internally used.  */
00077   memset (attr, '\0', sizeof (struct old_attr));
00078 
00079   iattr = (struct pthread_attr *) attr;
00080   iattr->flags |= ATTR_FLAG_OLDATTR;
00081 
00082   /* We cannot enqueue the attribute because that member is not in the
00083      old attribute structure.  */
00084   return 0;
00085 }
00086 compat_symbol (libpthread, __pthread_attr_init_2_0, pthread_attr_init,
00087               GLIBC_2_0);
00088 #endif