]> git.ipfire.org Git - thirdparty/glibc.git/blame - nptl/pthread_rwlock_init.c
stdlib: Fix tst-makecontext2 log when swapcontext fails
[thirdparty/glibc.git] / nptl / pthread_rwlock_init.c
CommitLineData
dff8da6b 1/* Copyright (C) 2002-2024 Free Software Foundation, Inc.
76a50749 2 This file is part of the GNU C Library.
76a50749
UD
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
59ba27a6 15 License along with the GNU C Library; if not, see
5a82c748 16 <https://www.gnu.org/licenses/>. */
76a50749
UD
17
18#include "pthreadP.h"
c71ca1f8 19#include <string.h>
48dbce60 20#include <pthread-offsets.h>
63627246 21#include <shlib-compat.h>
76a50749 22
69854bb5 23static const struct pthread_rwlockattr default_rwlockattr =
76a50749
UD
24 {
25 .lockkind = PTHREAD_RWLOCK_DEFAULT_NP,
26 .pshared = PTHREAD_PROCESS_PRIVATE
27 };
28
29
cc25c8b4 30/* See pthread_rwlock_common.c. */
76a50749 31int
63627246 32___pthread_rwlock_init (pthread_rwlock_t *rwlock,
f63f2bfd 33 const pthread_rwlockattr_t *attr)
76a50749 34{
72b3c6ee
AZ
35 ASSERT_TYPE_SIZE (pthread_rwlock_t, __SIZEOF_PTHREAD_RWLOCK_T);
36
48dbce60
AZ
37 /* The __flags is the only field where its offset should be checked to
38 avoid ABI breakage with static initializers. */
39 ASSERT_PTHREAD_INTERNAL_OFFSET (pthread_rwlock_t, __data.__flags,
40 __PTHREAD_RWLOCK_FLAGS_OFFSET);
41 ASSERT_PTHREAD_INTERNAL_MEMBER_SIZE (pthread_rwlock_t, __data.__flags,
42 int);
43
76a50749
UD
44 const struct pthread_rwlockattr *iattr;
45
69854bb5 46 iattr = ((const struct pthread_rwlockattr *) attr) ?: &default_rwlockattr;
76a50749 47
f01c2359 48 memset (rwlock, '\0', sizeof (*rwlock));
e59660bc 49
cc25c8b4 50 rwlock->__data.__flags = iattr->lockkind;
e59660bc 51
cc25c8b4
TR
52 /* The value of __SHARED in a private rwlock must be zero. */
53 rwlock->__data.__shared = (iattr->pshared != PTHREAD_PROCESS_PRIVATE);
e59660bc 54
76a50749
UD
55 return 0;
56}
63627246
FW
57versioned_symbol (libc, ___pthread_rwlock_init, pthread_rwlock_init,
58 GLIBC_2_34);
59libc_hidden_ver (___pthread_rwlock_init, __pthread_rwlock_init)
60#ifndef SHARED
61strong_alias (___pthread_rwlock_init, __pthread_rwlock_init)
62#endif
63
64#if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_1, GLIBC_2_34)
65compat_symbol (libpthread, ___pthread_rwlock_init, pthread_rwlock_init,
66 GLIBC_2_1);
67#endif
68#if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_2, GLIBC_2_34)
69compat_symbol (libpthread, ___pthread_rwlock_init, __pthread_rwlock_init,
70 GLIBC_2_2);
71#endif