Skip to content

Commit a1aba84

Browse files
authored
[libc] Reland #148948 "Implement barriers for pthreads" (#151021)
Fixed build dependencies for pthread_barrier_t (add __barrier_type to cmake dependencies)
1 parent a653934 commit a1aba84

25 files changed

+625
-0
lines changed

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,9 @@ if(LLVM_LIBC_FULL_BUILD)
10561056
libc.src.pthread.pthread_join
10571057
libc.src.pthread.pthread_key_create
10581058
libc.src.pthread.pthread_key_delete
1059+
libc.src.pthread.pthread_barrier_init
1060+
libc.src.pthread.pthread_barrier_wait
1061+
libc.src.pthread.pthread_barrier_destroy
10591062
libc.src.pthread.pthread_mutex_destroy
10601063
libc.src.pthread.pthread_mutex_init
10611064
libc.src.pthread.pthread_mutex_lock

libc/hdr/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ add_proxy_header_library(
7272
libc.include.fenv
7373
)
7474

75+
add_proxy_header_library(
76+
pthread_macros
77+
HDRS
78+
pthread_macros.h
79+
FULL_BUILD_DEPENDS
80+
libc.include.llvm-libc-macros.pthread_macros
81+
libc.include.pthread
82+
)
83+
7584
add_proxy_header_library(
7685
sched_macros
7786
HDRS

libc/hdr/pthread_macros.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Definition of macros from pthread.h -------------------------------===//
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_HDR_PTHREAD_MACROS_H
10+
#define LLVM_LIBC_HDR_PTHREAD_MACROS_H
11+
12+
#ifdef LIBC_FULL_BUILD
13+
14+
#include "include/llvm-libc-macros/pthread-macros.h"
15+
16+
#else // Overlay mode
17+
18+
#include <pthread.h>
19+
20+
#endif // LLVM_LIBC_FULL_BUILD
21+
22+
#endif // LLVM_LIBC_HDR_PTHREAD_MACROS_H

libc/hdr/types/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,22 @@ add_proxy_header_library(
241241
libc.include.llvm-libc-types.pid_t
242242
)
243243

244+
add_proxy_header_library(
245+
pthread_barrier_t
246+
HDRS
247+
pthread_barrier_t.h
248+
FULL_BUILD_DEPENDS
249+
libc.include.llvm-libc-types.pthread_barrier_t
250+
)
251+
252+
add_proxy_header_library(
253+
pthread_barrierattr_t
254+
HDRS
255+
pthread_barrierattr_t.h
256+
FULL_BUILD_DEPENDS
257+
libc.include.llvm-libc-types.pthread_barrierattr_t
258+
)
259+
244260
add_proxy_header_library(
245261
atexithandler_t
246262
HDRS

libc/hdr/types/pthread_barrier_t.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Definition of macros from pthread_barrier_t.h ---------------------===//
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_HDR_TYPES_PTHREAD_BARRIER_T_H
10+
#define LLVM_LIBC_HDR_TYPES_PTHREAD_BARRIER_T_H
11+
12+
#ifdef LIBC_FULL_BUILD
13+
14+
#include "include/llvm-libc-types/pthread_barrier_t.h"
15+
16+
#else // Overlay mode
17+
18+
#error "Cannot overlay pthread_barrier_t"
19+
20+
#endif // LLVM_LIBC_FULL_BUILD
21+
22+
#endif // LLVM_LIBC_HDR_TYPES_PTHREAD_BARRIER_T_H
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- Definition of macros from pthread_barrierattr_t.h -----------------===//
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_HDR_TYPES_PTHREAD_BARRIERATTR_T_H
10+
#define LLVM_LIBC_HDR_TYPES_PTHREAD_BARRIERATTR_T_H
11+
12+
#ifdef LIBC_FULL_BUILD
13+
14+
#include "include/llvm-libc-types/pthread_barrierattr_t.h"
15+
16+
#else // Overlay mode
17+
18+
#error "Cannot overlay pthread_barrierattr_t"
19+
20+
#endif // LLVM_LIBC_FULL_BUILD
21+
22+
#endif // LLVM_LIBC_HDR_TYPES_PTHREAD_BARRIERATTR_T_H

libc/include/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ add_header_macro(
392392
.llvm-libc-types.pthread_attr_t
393393
.llvm-libc-types.pthread_condattr_t
394394
.llvm-libc-types.pthread_key_t
395+
.llvm-libc-types.pthread_barrier_t
396+
.llvm-libc-types.pthread_barrierattr_t
395397
.llvm-libc-types.pthread_mutex_t
396398
.llvm-libc-types.pthread_mutexattr_t
397399
.llvm-libc-types.pthread_once_t

libc/include/llvm-libc-macros/pthread-macros.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#define PTHREAD_MUTEX_STALLED 0
2323
#define PTHREAD_MUTEX_ROBUST 1
2424

25+
#define PTHREAD_BARRIER_SERIAL_THREAD -1
26+
2527
#define PTHREAD_ONCE_INIT {0}
2628

2729
#define PTHREAD_PROCESS_PRIVATE 0

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ add_header(__exec_envp_t HDR __exec_envp_t.h)
1010
add_header(__futex_word HDR __futex_word.h)
1111
add_header(pid_t HDR pid_t.h)
1212
add_header(__mutex_type HDR __mutex_type.h DEPENDS .__futex_word .pid_t)
13+
add_header(__barrier_type HDR __barrier_type.h)
1314
add_header(__pthread_once_func_t HDR __pthread_once_func_t.h)
1415
add_header(__pthread_start_t HDR __pthread_start_t.h)
1516
add_header(__pthread_tss_dtor_t HDR __pthread_tss_dtor_t.h)
@@ -53,6 +54,8 @@ add_header(pthread_condattr_t HDR pthread_condattr_t.h DEPENDS .clockid_t)
5354
add_header(pthread_key_t HDR pthread_key_t.h)
5455
add_header(pthread_mutex_t HDR pthread_mutex_t.h DEPENDS .__futex_word .__mutex_type)
5556
add_header(pthread_mutexattr_t HDR pthread_mutexattr_t.h)
57+
add_header(pthread_barrier_t HDR pthread_barrier_t.h DEPENDS .__barrier_type)
58+
add_header(pthread_barrierattr_t HDR pthread_barrierattr_t.h)
5659
add_header(pthread_once_t HDR pthread_once_t.h DEPENDS .__futex_word)
5760
add_header(pthread_rwlock_t HDR pthread_rwlock_t.h DEPENDS .__futex_word .pid_t)
5861
add_header(pthread_rwlockattr_t HDR pthread_rwlockattr_t.h)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Definition of __barrier_type 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+
9+
#ifndef LLVM_LIBC_TYPES__BARRIER_TYPE_H
10+
#define LLVM_LIBC_TYPES__BARRIER_TYPE_H
11+
12+
typedef struct __attribute__((aligned(8 /* alignof (Barrier) */))) {
13+
unsigned expected;
14+
unsigned waiting;
15+
bool blocking;
16+
char entering[24 /* sizeof (CndVar) */];
17+
char exiting[24 /* sizeof (CndVar) */];
18+
char mutex[24 /* sizeof (Mutex) */];
19+
} __barrier_type;
20+
21+
#endif // LLVM_LIBC_TYPES__BARRIER_TYPE_H

0 commit comments

Comments
 (0)