Hurd: fix mode type for openat
[glibc.git] / nptl / pthread_barrier_init.c
blob1aaa2a4eb0b1fc974680d50205214fe9fa1e2280
1 /* Copyright (C) 2002, 2007 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <errno.h>
20 #include "pthreadP.h"
21 #include <lowlevellock.h>
22 #include <kernel-features.h>
25 static const struct pthread_barrierattr default_attr =
27 .pshared = PTHREAD_PROCESS_PRIVATE
31 int
32 pthread_barrier_init (barrier, attr, count)
33 pthread_barrier_t *barrier;
34 const pthread_barrierattr_t *attr;
35 unsigned int count;
37 struct pthread_barrier *ibarrier;
39 if (__builtin_expect (count == 0, 0))
40 return EINVAL;
42 const struct pthread_barrierattr *iattr
43 = (attr != NULL
44 ? iattr = (struct pthread_barrierattr *) attr
45 : &default_attr);
47 if (iattr->pshared != PTHREAD_PROCESS_PRIVATE
48 && __builtin_expect (iattr->pshared != PTHREAD_PROCESS_SHARED, 0))
49 /* Invalid attribute. */
50 return EINVAL;
52 ibarrier = (struct pthread_barrier *) barrier;
54 /* Initialize the individual fields. */
55 ibarrier->lock = LLL_LOCK_INITIALIZER;
56 ibarrier->left = count;
57 ibarrier->init_count = count;
58 ibarrier->curr_event = 0;
60 #ifdef __ASSUME_PRIVATE_FUTEX
61 ibarrier->private = (iattr->pshared != PTHREAD_PROCESS_PRIVATE
62 ? 0 : FUTEX_PRIVATE_FLAG);
63 #else
64 ibarrier->private = (iattr->pshared != PTHREAD_PROCESS_PRIVATE
65 ? 0 : THREAD_GETMEM (THREAD_SELF,
66 header.private_futex));
67 #endif
69 return 0;