]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - nptl/sem_open.c
Update copyright notices with scripts/update-copyrights.
[thirdparty/glibc.git] / nptl / sem_open.c
index 66bcb13aec4339377d60544caf7b95d1b7f1f2b7..5bc56c5bd908b19000f986bcfce6f5763f32503c 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002, 2003, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 2002-2013 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
 
@@ -13,9 +13,8 @@
    Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
 
 #include <errno.h>
 #include <fcntl.h>
@@ -147,7 +146,7 @@ __sem_search (const void *a, const void *b)
 void *__sem_mappings attribute_hidden;
 
 /* Lock to protect the search tree.  */
-lll_lock_t __sem_mappings_lock attribute_hidden = LLL_LOCK_INITIALIZER;
+int __sem_mappings_lock attribute_hidden = LLL_LOCK_INITIALIZER;
 
 
 /* Search for existing mapping and if possible add the one provided.  */
@@ -161,7 +160,7 @@ check_add_mapping (const char *name, size_t namelen, int fd, sem_t *existing)
   if (__fxstat64 (_STAT_VER, fd, &st) == 0)
     {
       /* Get the lock.  */
-      lll_lock (__sem_mappings_lock);
+      lll_lock (__sem_mappings_lock, LLL_PRIVATE);
 
       /* Search for an existing mapping given the information we have.  */
       struct inuse_sem *fake;
@@ -210,7 +209,7 @@ check_add_mapping (const char *name, size_t namelen, int fd, sem_t *existing)
        }
 
       /* Release the lock.  */
-      lll_unlock (__sem_mappings_lock);
+      lll_unlock (__sem_mappings_lock, LLL_PRIVATE);
     }
 
   if (result != existing && existing != SEM_FAILED && existing != MAP_FAILED)
@@ -232,7 +231,7 @@ sem_open (const char *name, int oflag, ...)
   int fd;
 
   /* Determine where the shmfs is mounted.  */
-  INTUSE(__pthread_once) (&__namedsem_once, __where_is_shmfs);
+  __pthread_once (&__namedsem_once, __where_is_shmfs);
 
   /* If we don't know the mount points there is nothing we can do.  Ever.  */
   if (mountpoint.dir == NULL)
@@ -302,14 +301,19 @@ sem_open (const char *name, int oflag, ...)
        }
 
       /* Create the initial file content.  */
-      sem_t initsem;
+      union
+      {
+       sem_t initsem;
+       struct new_sem newsem;
+      } sem;
 
-      struct sem *iinitsem = (struct sem *) &initsem;
-      iinitsem->count = value;
+      sem.newsem.value = value;
+      sem.newsem.private = 0;
+      sem.newsem.nwaiters = 0;
 
       /* Initialize the remaining bytes as well.  */
-      memset ((char *) &initsem + sizeof (struct sem), '\0',
-             sizeof (sem_t) - sizeof (struct sem));
+      memset ((char *) &sem.initsem + sizeof (struct new_sem), '\0',
+             sizeof (sem_t) - sizeof (struct new_sem));
 
       tmpfname = (char *) alloca (mountpoint.dirlen + 6 + 1);
       char *xxxxxx = __mempcpy (tmpfname, mountpoint.dir, mountpoint.dirlen);
@@ -347,7 +351,7 @@ sem_open (const char *name, int oflag, ...)
          break;
        }
 
-      if (TEMP_FAILURE_RETRY (__libc_write (fd, &initsem, sizeof (sem_t)))
+      if (TEMP_FAILURE_RETRY (__libc_write (fd, &sem.initsem, sizeof (sem_t)))
          == sizeof (sem_t)
          /* Map the sem_t structure from the file.  */
          && (result = (sem_t *) mmap (NULL, sizeof (sem_t),