Skip to content

Commit 8f7ebfc

Browse files
[libc][POSIX][pthreads] implement pthread_condattr_t functions
Implement: - pthread_condattr_destroy - pthread_condattr_getclock - pthread_condattr_getpshared - pthread_condattr_init - pthread_condattr_setclock - pthread_condattr_setpshared Fixes: #88581
1 parent 6d23463 commit 8f7ebfc

22 files changed

+539
-8
lines changed

libc/config/linux/api.td

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ def PThreadAPI : PublicAPI<"pthread.h"> {
175175
"__pthread_start_t",
176176
"__pthread_tss_dtor_t",
177177
"pthread_attr_t",
178+
"pthread_condattr_t",
178179
"pthread_mutex_t",
179180
"pthread_mutexattr_t",
180181
"pthread_t",
@@ -241,10 +242,30 @@ def SysSendfileAPI : PublicAPI<"sys/sendfile.h"> {
241242
}
242243

243244
def SysTypesAPI : PublicAPI<"sys/types.h"> {
244-
let Types = ["blkcnt_t", "blksize_t", "clockid_t", "dev_t", "gid_t", "ino_t",
245-
"mode_t", "nlink_t", "off_t", "pid_t", "pthread_attr_t", "pthread_key_t",
246-
"pthread_mutex_t", "pthread_mutexattr_t", "pthread_once_t", "pthread_t",
247-
"size_t", "ssize_t", "suseconds_t", "time_t", "uid_t"];
245+
let Types = [
246+
"blkcnt_t",
247+
"blksize_t",
248+
"clockid_t",
249+
"dev_t",
250+
"gid_t",
251+
"ino_t",
252+
"mode_t",
253+
"nlink_t",
254+
"off_t",
255+
"pid_t",
256+
"pthread_attr_t",
257+
"pthread_condattr_t",
258+
"pthread_key_t",
259+
"pthread_mutex_t",
260+
"pthread_mutexattr_t",
261+
"pthread_once_t",
262+
"pthread_t",
263+
"size_t",
264+
"ssize_t",
265+
"suseconds_t",
266+
"time_t",
267+
"uid_t"
268+
];
248269
}
249270

250271
def SysUtsNameAPI : PublicAPI<"sys/utsname.h"> {

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,12 @@ if(LLVM_LIBC_FULL_BUILD)
638638
libc.src.pthread.pthread_attr_setguardsize
639639
libc.src.pthread.pthread_attr_setstack
640640
libc.src.pthread.pthread_attr_setstacksize
641+
libc.src.pthread.pthread_condattr_destroy
642+
libc.src.pthread.pthread_condattr_getclock
643+
libc.src.pthread.pthread_condattr_getpshared
644+
libc.src.pthread.pthread_condattr_init
645+
libc.src.pthread.pthread_condattr_setclock
646+
libc.src.pthread.pthread_condattr_setpshared
641647
libc.src.pthread.pthread_create
642648
libc.src.pthread.pthread_detach
643649
libc.src.pthread.pthread_equal

libc/include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ add_gen_header(
321321
.llvm-libc-types.__pthread_start_t
322322
.llvm-libc-types.__pthread_tss_dtor_t
323323
.llvm-libc-types.pthread_attr_t
324+
.llvm-libc-types.pthread_condattr_t
324325
.llvm-libc-types.pthread_mutex_t
325326
.llvm-libc-types.pthread_mutexattr_t
326327
.llvm-libc-types.pthread_t

libc/include/llvm-libc-types/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ add_header(pid_t HDR pid_t.h)
4949
add_header(posix_spawn_file_actions_t HDR posix_spawn_file_actions_t.h)
5050
add_header(posix_spawnattr_t HDR posix_spawnattr_t.h)
5151
add_header(pthread_attr_t HDR pthread_attr_t.h DEPENDS .size_t)
52+
add_header(pthread_condattr_t HDR pthread_condattr_t.h DEPENDS .clockid_t)
5253
add_header(pthread_key_t HDR pthread_key_t.h)
5354
add_header(pthread_mutex_t HDR pthread_mutex_t.h DEPENDS .__futex_word .__mutex_type)
54-
add_header(pthread_t HDR pthread_t.h DEPENDS .__thread_type)
5555
add_header(pthread_mutexattr_t HDR pthread_mutexattr_t.h)
5656
add_header(pthread_once_t HDR pthread_once_t.h DEPENDS .__futex_word)
57+
add_header(pthread_t HDR pthread_t.h DEPENDS .__thread_type)
5758
add_header(rlim_t HDR rlim_t.h)
5859
add_header(time_t HDR time_t.h)
5960
add_header(stack_t HDR stack_t.h)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===-- Definition of pthread_condattr_t type -----------------------------===//
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+
#ifndef LLVM_LIBC_TYPES_PTHREAD_CONDATTR_T_H
9+
#define LLVM_LIBC_TYPES_PTHREAD_CONDATTR_T_H
10+
11+
#include "clockid_t.h"
12+
13+
typedef struct {
14+
clockid_t clock;
15+
int pshared;
16+
} pthread_condattr_t;
17+
18+
#endif // LLVM_LIBC_TYPES_PTHREAD_CONDATTR_T_H

libc/include/pthread.h.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ enum {
3232
PTHREAD_MUTEX_ROBUST = 0x1,
3333
};
3434

35+
#define PTHREAD_PROCESS_PRIVATE 0
36+
#define PTHREAD_PROCESS_SHARED 1
37+
3538
%%public_api()
3639

3740
#endif // LLVM_LIBC_PTHREAD_H

libc/spec/posix.td

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def UidT : NamedType<"uid_t">;
2626
def GidT : NamedType<"gid_t">;
2727
def DevT : NamedType<"dev_t">;
2828
def ClockIdT : NamedType<"clockid_t">;
29+
def RestrictedClockIdTPtr : RestrictedPtrType<ClockIdT>;
2930
def BlkSizeT : NamedType<"blksize_t">;
3031
def BlkCntT : NamedType<"blkcnt_t">;
3132
def NLinkT : NamedType<"nlink_t">;
@@ -105,6 +106,10 @@ def POSIX : StandardSpec<"POSIX"> {
105106
ConstType ConstPThreadAttrTPtr = ConstType<PThreadAttrTPtr>;
106107
ConstType ConstRestrictedPThreadAttrTPtr = ConstType<RestrictedPThreadAttrTPtr>;
107108

109+
NamedType PThreadCondAttrTType = NamedType<"pthread_condattr_t">;
110+
PtrType PThreadCondAttrTPtr = PtrType<PThreadCondAttrTType>;
111+
ConstType ConstRestrictedPThreadCondAttrTPtr = ConstType<RestrictedPtrType<PThreadCondAttrTType>>;
112+
108113
NamedType PThreadMutexAttrTType = NamedType<"pthread_mutexattr_t">;
109114
PtrType PThreadMutexAttrTPtr = PtrType<PThreadMutexAttrTType>;
110115
RestrictedPtrType RestrictedPThreadMutexAttrTPtr = RestrictedPtrType<PThreadMutexAttrTType>;
@@ -980,7 +985,9 @@ def POSIX : StandardSpec<"POSIX"> {
980985
[], // Macros
981986
[
982987
AtForkCallbackT,
988+
ClockIdT,
983989
PThreadAttrTType,
990+
PThreadCondAttrTType,
984991
PThreadKeyT,
985992
PThreadMutexAttrTType,
986993
PThreadMutexTType,
@@ -1047,6 +1054,36 @@ def POSIX : StandardSpec<"POSIX"> {
10471054
RetValSpec<IntType>,
10481055
[ArgSpec<PThreadAttrTPtr>, ArgSpec<VoidPtr>, ArgSpec<SizeTType>]
10491056
>,
1057+
FunctionSpec<
1058+
"pthread_condattr_destroy",
1059+
RetValSpec<IntType>,
1060+
[ArgSpec<PThreadCondAttrTPtr>]
1061+
>,
1062+
FunctionSpec<
1063+
"pthread_condattr_getclock",
1064+
RetValSpec<IntType>,
1065+
[ArgSpec<ConstRestrictedPThreadCondAttrTPtr>, ArgSpec<RestrictedClockIdTPtr>]
1066+
>,
1067+
FunctionSpec<
1068+
"pthread_condattr_getpshared",
1069+
RetValSpec<IntType>,
1070+
[ArgSpec<ConstRestrictedPThreadCondAttrTPtr>, ArgSpec<RestrictedIntPtr>]
1071+
>,
1072+
FunctionSpec<
1073+
"pthread_condattr_init",
1074+
RetValSpec<IntType>,
1075+
[ArgSpec<PThreadCondAttrTPtr>]
1076+
>,
1077+
FunctionSpec<
1078+
"pthread_condattr_setclock",
1079+
RetValSpec<IntType>,
1080+
[ArgSpec<PThreadCondAttrTPtr>, ArgSpec<ClockIdT>]
1081+
>,
1082+
FunctionSpec<
1083+
"pthread_condattr_setpshared",
1084+
RetValSpec<IntType>,
1085+
[ArgSpec<PThreadCondAttrTPtr>, ArgSpec<IntType>]
1086+
>,
10501087
FunctionSpec<
10511088
"pthread_create",
10521089
RetValSpec<IntType>,
@@ -1522,9 +1559,30 @@ def POSIX : StandardSpec<"POSIX"> {
15221559
HeaderSpec SysTypes = HeaderSpec<
15231560
"sys/types.h",
15241561
[], // Macros
1525-
[BlkCntT, BlkSizeT, ClockIdT, DevT, GidT, InoT, ModeTType, NLinkT, OffTType, PidT,
1526-
PThreadAttrTType, PThreadKeyT, PThreadMutexTType, PThreadMutexAttrTType, PThreadOnceT, PThreadTType,
1527-
SizeTType, SSizeTType, SuSecondsT, TimeTType, UidT],
1562+
[
1563+
BlkCntT,
1564+
BlkSizeT,
1565+
ClockIdT,
1566+
DevT,
1567+
GidT,
1568+
InoT,
1569+
ModeTType,
1570+
NLinkT,
1571+
OffTType,
1572+
PThreadAttrTType,
1573+
PThreadCondAttrTType,
1574+
PThreadKeyT,
1575+
PThreadMutexAttrTType,
1576+
PThreadMutexTType,
1577+
PThreadOnceT,
1578+
PThreadTType,
1579+
PidT,
1580+
SSizeTType,
1581+
SizeTType,
1582+
SuSecondsT,
1583+
TimeTType,
1584+
UidT
1585+
], // Types
15281586
[], // Enumerations
15291587
[] // Functions
15301588
>;

libc/src/pthread/CMakeLists.txt

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,71 @@ add_entrypoint_object(
100100
libc.src.pthread.pthread_attr_setstacksize
101101
)
102102

103+
add_entrypoint_object(
104+
pthread_condattr_destroy
105+
SRCS
106+
pthread_condattr_destroy.cpp
107+
HDRS
108+
pthread_condattr_destroy.h
109+
DEPENDS
110+
libc.include.pthread
111+
)
112+
113+
add_entrypoint_object(
114+
pthread_condattr_getclock
115+
SRCS
116+
pthread_condattr_getclock.cpp
117+
HDRS
118+
pthread_condattr_getclock.h
119+
DEPENDS
120+
libc.include.pthread
121+
libc.include.sys_types
122+
)
123+
124+
add_entrypoint_object(
125+
pthread_condattr_getpshared
126+
SRCS
127+
pthread_condattr_getpshared.cpp
128+
HDRS
129+
pthread_condattr_getpshared.h
130+
DEPENDS
131+
libc.include.pthread
132+
)
133+
134+
add_entrypoint_object(
135+
pthread_condattr_init
136+
SRCS
137+
pthread_condattr_init.cpp
138+
HDRS
139+
pthread_condattr_init.h
140+
DEPENDS
141+
libc.include.pthread
142+
libc.include.time
143+
)
144+
145+
add_entrypoint_object(
146+
pthread_condattr_setclock
147+
SRCS
148+
pthread_condattr_setclock.cpp
149+
HDRS
150+
pthread_condattr_setclock.h
151+
DEPENDS
152+
libc.include.errno
153+
libc.include.pthread
154+
libc.include.sys_types
155+
libc.include.time
156+
)
157+
158+
add_entrypoint_object(
159+
pthread_condattr_setpshared
160+
SRCS
161+
pthread_condattr_setpshared.cpp
162+
HDRS
163+
pthread_condattr_setpshared.h
164+
DEPENDS
165+
libc.include.pthread
166+
)
167+
103168
add_header_library(
104169
pthread_mutexattr
105170
HDRS
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Implementation of the pthread_condattr_destroy --------------------===//
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_condattr_destroy.h"
10+
11+
#include "src/__support/common.h"
12+
13+
#include <pthread.h>
14+
15+
namespace LIBC_NAMESPACE {
16+
17+
LLVM_LIBC_FUNCTION(int, pthread_condattr_destroy, (pthread_condattr_t * attr)) {
18+
return 0;
19+
}
20+
21+
} // 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_condattr_destroy ------*- 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_CONDATTR_DESTROY_H
10+
#define LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_DESTROY_H
11+
12+
#include <pthread.h>
13+
14+
namespace LIBC_NAMESPACE {
15+
16+
int pthread_condattr_destroy(pthread_condattr_t *attr);
17+
18+
} // namespace LIBC_NAMESPACE
19+
20+
#endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_DESTROY_H
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===-- Implementation of the pthread_condattr_getclock -------------------===//
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_condattr_getclock.h"
10+
11+
#include "src/__support/common.h"
12+
13+
#include <pthread.h> // pthread_condattr_t
14+
#include <sys/types.h> // clockid_t
15+
16+
namespace LIBC_NAMESPACE {
17+
18+
LLVM_LIBC_FUNCTION(int, pthread_condattr_getclock,
19+
(const pthread_condattr_t *__restrict attr,
20+
clockid_t *__restrict clock_id)) {
21+
*clock_id = attr->clock;
22+
return 0;
23+
}
24+
25+
} // namespace LIBC_NAMESPACE
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Implementation header for pthread_condattr_getclock -----*- 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_CONDATTR_GETCLOCK_H
10+
#define LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_GETCLOCK_H
11+
12+
#include <pthread.h> // pthread_condattr_t
13+
#include <sys/types.h> // clockid_t
14+
15+
namespace LIBC_NAMESPACE {
16+
17+
int pthread_condattr_getclock(const pthread_condattr_t *__restrict attr,
18+
clockid_t *__restrict clock_id);
19+
20+
} // namespace LIBC_NAMESPACE
21+
22+
#endif // LLVM_LIBC_SRC_PTHREAD_PTHREAD_CONDATTR_GETCLOCK_H
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//===-- Implementation of the pthread_condattr_getpshared -----------------===//
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_condattr_getpshared.h"
10+
11+
#include "src/__support/common.h"
12+
13+
#include <pthread.h>
14+
15+
namespace LIBC_NAMESPACE {
16+
17+
LLVM_LIBC_FUNCTION(int, pthread_condattr_getpshared,
18+
(const pthread_condattr_t *__restrict attr,
19+
int *__restrict pshared)) {
20+
*pshared = attr->pshared;
21+
return 0;
22+
}
23+
24+
} // namespace LIBC_NAMESPACE

0 commit comments

Comments
 (0)