]> git.ipfire.org Git - thirdparty/glibc.git/blame - nptl/pthread_barrier_init.c
Update copyright notices with scripts/update-copyrights
[thirdparty/glibc.git] / nptl / pthread_barrier_init.c
CommitLineData
d4697bc9 1/* Copyright (C) 2002-2014 Free Software Foundation, Inc.
76a50749
UD
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
4
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.
9
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.
14
15 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
76a50749
UD
18
19#include <errno.h>
20#include "pthreadP.h"
21#include <lowlevellock.h>
d8ff3792
UD
22#include <kernel-features.h>
23
24
69854bb5 25static const struct pthread_barrierattr default_barrierattr =
d8ff3792
UD
26 {
27 .pshared = PTHREAD_PROCESS_PRIVATE
28 };
76a50749
UD
29
30
31int
32pthread_barrier_init (barrier, attr, count)
33 pthread_barrier_t *barrier;
34 const pthread_barrierattr_t *attr;
35 unsigned int count;
36{
37 struct pthread_barrier *ibarrier;
38
39 if (__builtin_expect (count == 0, 0))
40 return EINVAL;
41
e51deae7 42 const struct pthread_barrierattr *iattr
d8ff3792
UD
43 = (attr != NULL
44 ? iattr = (struct pthread_barrierattr *) attr
69854bb5 45 : &default_barrierattr);
76a50749 46
d8ff3792
UD
47 if (iattr->pshared != PTHREAD_PROCESS_PRIVATE
48 && __builtin_expect (iattr->pshared != PTHREAD_PROCESS_SHARED, 0))
49 /* Invalid attribute. */
50 return EINVAL;
76a50749
UD
51
52 ibarrier = (struct pthread_barrier *) barrier;
53
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;
59
d8ff3792
UD
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
68
76a50749
UD
69 return 0;
70}