Back to index

glibc  2.9
sem_init.c
Go to the documentation of this file.
00001 /* Copyright (C) 2002, 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 <errno.h>
00021 #include <string.h>
00022 #include <semaphore.h>
00023 #include <lowlevellock.h>
00024 #include <shlib-compat.h>
00025 #include "semaphoreP.h"
00026 #include <kernel-features.h>
00027 
00028 
00029 int
00030 __new_sem_init (sem, pshared, value)
00031      sem_t *sem;
00032      int pshared;
00033      unsigned int value;
00034 {
00035   /* Parameter sanity check.  */
00036   if (__builtin_expect (value > SEM_VALUE_MAX, 0))
00037     {
00038       __set_errno (EINVAL);
00039       return -1;
00040     }
00041 
00042   /* Map to the internal type.  */
00043   struct sparc_new_sem *isem = (struct sparc_new_sem *) sem;
00044 
00045   /* Use the values the user provided.  */
00046   memset (isem, '\0', sizeof (*isem));
00047   isem->value = value;
00048 #ifdef __ASSUME_PRIVATE_FUTEX
00049   isem->private = pshared ? 0 : FUTEX_PRIVATE_FLAG;
00050 #else
00051   isem->private = pshared ? 0 : THREAD_GETMEM (THREAD_SELF,
00052                                           header.private_futex);
00053 #endif
00054 
00055   return 0;
00056 }
00057 versioned_symbol (libpthread, __new_sem_init, sem_init, GLIBC_2_1);
00058 
00059 
00060 
00061 #if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_1)
00062 int
00063 attribute_compat_text_section
00064 __old_sem_init (sem, pshared, value)
00065      sem_t *sem;
00066      int pshared;
00067      unsigned int value;
00068 {
00069   /* Parameter sanity check.  */
00070   if (__builtin_expect (value > SEM_VALUE_MAX, 0))
00071     {
00072       __set_errno (EINVAL);
00073       return -1;
00074     }
00075 
00076   /* Map to the internal type.  */
00077   struct sparc_old_sem *isem = (struct sparc_old_sem *) sem;
00078 
00079   /* Use the value the user provided.  */
00080   memset (isem, '\0', sizeof (*isem));
00081   isem->value = value;
00082 
00083 #ifdef __ASSUME_PRIVATE_FUTEX
00084   isem->private = pshared ? 0 : FUTEX_PRIVATE_FLAG;
00085 #else
00086   isem->private = pshared ? 0 : THREAD_GETMEM (THREAD_SELF,
00087                                           header.private_futex);
00088 #endif
00089 
00090   return 0;
00091 }
00092 compat_symbol (libpthread, __old_sem_init, sem_init, GLIBC_2_0);
00093 #endif