Skip to content

Commit 485f9f5

Browse files
Reland: [libc][POSIX][pthreads] implemented missing pthread_rwlockattr functions (llvm#93622)
New pull request for llvm#89443 The previous PR was reverted after breaking fullbuild due to a missing struct declaration, which I forgot to commit. Reverts revert and adds the missing pthread_rwlockattr_getkind_np / pthread_rwlockattr_setkind_np functions and tests respecitvely.
1 parent 5785048 commit 485f9f5

12 files changed

+163
-3
lines changed

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,8 +673,10 @@ if(LLVM_LIBC_FULL_BUILD)
673673
libc.src.pthread.pthread_mutexattr_settype
674674
libc.src.pthread.pthread_once
675675
libc.src.pthread.pthread_rwlockattr_destroy
676+
libc.src.pthread.pthread_rwlockattr_getkind_np
676677
libc.src.pthread.pthread_rwlockattr_getpshared
677678
libc.src.pthread.pthread_rwlockattr_init
679+
libc.src.pthread.pthread_rwlockattr_setkind_np
678680
libc.src.pthread.pthread_rwlockattr_setpshared
679681
libc.src.pthread.pthread_setspecific
680682

libc/include/llvm-libc-types/pthread_rwlockattr_t.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
typedef struct {
1212
int pshared;
13+
int pref;
1314
} pthread_rwlockattr_t;
1415

1516
#endif // LLVM_LIBC_TYPES_PTHREAD_RWLOCKATTR_T_H

libc/include/pthread.h.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ enum {
3838
#define PTHREAD_PROCESS_PRIVATE 0
3939
#define PTHREAD_PROCESS_SHARED 1
4040

41+
#define PTHREAD_RWLOCK_PREFER_READER_NP 0
42+
#define PTHREAD_RWLOCK_PREFER_WRITER_NP 1
43+
#define PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP 2
44+
45+
4146
%%public_api()
4247

4348
#endif // LLVM_LIBC_PTHREAD_H

libc/spec/posix.td

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,11 @@ def POSIX : StandardSpec<"POSIX"> {
12341234
RetValSpec<IntType>,
12351235
[ArgSpec<PThreadRWLockAttrTPtr>]
12361236
>,
1237+
FunctionSpec<
1238+
"pthread_rwlockattr_getkind_np",
1239+
RetValSpec<IntType>,
1240+
[ArgSpec<PThreadRWLockAttrTPtr>, ArgSpec<IntPtr>]
1241+
>,
12371242
FunctionSpec<
12381243
"pthread_rwlockattr_getpshared",
12391244
RetValSpec<IntType>,
@@ -1244,6 +1249,11 @@ def POSIX : StandardSpec<"POSIX"> {
12441249
RetValSpec<IntType>,
12451250
[ArgSpec<PThreadRWLockAttrTPtr>]
12461251
>,
1252+
FunctionSpec<
1253+
"pthread_rwlockattr_setkind_np",
1254+
RetValSpec<IntType>,
1255+
[ArgSpec<PThreadRWLockAttrTPtr>, ArgSpec<IntType>]
1256+
>,
12471257
FunctionSpec<
12481258
"pthread_rwlockattr_setpshared",
12491259
RetValSpec<IntType>,

libc/src/pthread/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,16 @@ add_entrypoint_object(
470470
libc.include.pthread
471471
)
472472

473+
add_entrypoint_object(
474+
pthread_rwlockattr_getkind_np
475+
SRCS
476+
pthread_rwlockattr_getkind_np.cpp
477+
HDRS
478+
pthread_rwlockattr_getkind_np.h
479+
DEPENDS
480+
libc.include.pthread
481+
)
482+
473483
add_entrypoint_object(
474484
pthread_rwlockattr_getpshared
475485
SRCS
@@ -490,6 +500,17 @@ add_entrypoint_object(
490500
libc.include.pthread
491501
)
492502

503+
add_entrypoint_object(
504+
pthread_rwlockattr_setkind_np
505+
SRCS
506+
pthread_rwlockattr_setkind_np.cpp
507+
HDRS
508+
pthread_rwlockattr_setkind_np.h
509+
DEPENDS
510+
libc.include.pthread
511+
libc.include.errno
512+
)
513+
493514
add_entrypoint_object(
494515
pthread_rwlockattr_setpshared
495516
SRCS
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//===-- Implementation of the pthread_rwlockattr_getkind_np ---------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "pthread_rwlockattr_getkind_np.h"
10+
11+
#include "src/__support/common.h"
12+
13+
#include <pthread.h> // pthread_rwlockattr_t
14+
15+
namespace LIBC_NAMESPACE {
16+
17+
LLVM_LIBC_FUNCTION(int, pthread_rwlockattr_getkind_np,
18+
(const pthread_rwlockattr_t *__restrict attr,
19+
int *__restrict pref)) {
20+
*pref = attr->pref;
21+
return 0;
22+
}
23+
24+
} // namespace LIBC_NAMESPACE
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Implementation header for pthread_rwlockattr_getkind_np -*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_PTHREAD_PTHREAD_RWLOCKATTR_GETKIND_NP_H
10+
#define LLVM_LIBC_SRC_PTHREAD_PTHREAD_RWLOCKATTR_GETKIND_NP_H
11+
12+
#include <pthread.h>
13+
14+
namespace LIBC_NAMESPACE {
15+
16+
int pthread_rwlockattr_getkind_np(const pthread_rwlockattr_t *__restrict attr,
17+
int *__restrict pref);
18+
19+
} // namespace LIBC_NAMESPACE
20+
21+
#endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_RWLOCKATTR_GETKIND_NP_H

libc/src/pthread/pthread_rwlockattr_init.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace LIBC_NAMESPACE {
1717
LLVM_LIBC_FUNCTION(int, pthread_rwlockattr_init,
1818
(pthread_rwlockattr_t * attr)) {
1919
attr->pshared = PTHREAD_PROCESS_PRIVATE;
20+
attr->pref = PTHREAD_RWLOCK_PREFER_READER_NP;
2021
return 0;
2122
}
2223

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//===-- Implementation of the pthread_rwlockattr_setkind_np ---------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "pthread_rwlockattr_setkind_np.h"
10+
11+
#include "src/__support/common.h"
12+
13+
#include <errno.h>
14+
#include <pthread.h> // pthread_rwlockattr_t
15+
16+
namespace LIBC_NAMESPACE {
17+
18+
LLVM_LIBC_FUNCTION(int, pthread_rwlockattr_setkind_np,
19+
(pthread_rwlockattr_t * attr, int pref)) {
20+
21+
if (pref != PTHREAD_RWLOCK_PREFER_READER_NP &&
22+
pref != PTHREAD_RWLOCK_PREFER_WRITER_NP &&
23+
pref != PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP)
24+
return EINVAL;
25+
26+
attr->pref = pref;
27+
return 0;
28+
}
29+
30+
} // namespace LIBC_NAMESPACE
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- Implementation header for pthread_rwlockattr_setkind_np -*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_PTHREAD_PTHREAD_RWLOCKATTR_SETKIND_NP_H
10+
#define LLVM_LIBC_SRC_PTHREAD_PTHREAD_RWLOCKATTR_SETKIND_NP_H
11+
12+
#include <pthread.h>
13+
14+
namespace LIBC_NAMESPACE {
15+
16+
int pthread_rwlockattr_setkind_np(pthread_rwlockattr_t *attr, int pref);
17+
18+
} // namespace LIBC_NAMESPACE
19+
20+
#endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_RWLOCKATTR_SETKIND_NP_H

0 commit comments

Comments
 (0)