Skip to content

Commit 8a25398

Browse files
[libc] move pthread macros to dedicated header (#119286)
so that docgen can find our definitions. Also eliminate the enums. POSIX is careful to call these "symbolic constants" rather than specifically whether they are preprocessor macro defines or not. Enums are useful to expressing mutual exclusion when the enum values are in distinct enums which can improve type safety. Our enum values weren't using that pattern though; they were all in one big anonymous enum. Link: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/pthread.h.html Fixes: #88997
1 parent 1d7d005 commit 8a25398

File tree

4 files changed

+46
-34
lines changed

4 files changed

+46
-34
lines changed

libc/include/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ add_header_macro(
389389
pthread.h.def
390390
pthread.h
391391
DEPENDS
392-
.llvm_libc_common_h
392+
.llvm-libc-macros.pthread_macros
393393
.llvm-libc-types.__atfork_callback_t
394394
.llvm-libc-types.__pthread_once_func_t
395395
.llvm-libc-types.__pthread_start_t
@@ -404,6 +404,7 @@ add_header_macro(
404404
.llvm-libc-types.pthread_rwlockattr_t
405405
.llvm-libc-types.pthread_spinlock_t
406406
.llvm-libc-types.pthread_t
407+
.llvm_libc_common_h
407408
)
408409

409410
add_header_macro(

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

+6
Original file line numberDiff line numberDiff line change
@@ -315,3 +315,9 @@ add_macro_header(
315315
HDR
316316
locale-macros.h
317317
)
318+
319+
add_macro_header(
320+
pthread_macros
321+
HDR
322+
pthread-macros.h
323+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===-- Definition of pthread macros --------------------------------------===//
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_MACROS_PTHREAD_MACRO_H
10+
#define LLVM_LIBC_MACROS_PTHREAD_MACRO_H
11+
12+
#define PTHREAD_CREATE_JOINABLE 0
13+
#define PTHREAD_CREATE_DETACHED 1
14+
15+
#define PTHREAD_MUTEX_NORMAL 0
16+
#define PTHREAD_MUTEX_ERRORCHECK 1
17+
#define PTHREAD_MUTEX_RECURSIVE 2
18+
#define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL
19+
20+
#define PTHREAD_MUTEX_STALLED 0
21+
#define PTHREAD_MUTEX_ROBUST 1
22+
23+
#define PTHREAD_ONCE_INIT {0}
24+
25+
#define PTHREAD_PROCESS_PRIVATE 0
26+
#define PTHREAD_PROCESS_SHARED 1
27+
28+
#define PTHREAD_MUTEX_INITIALIZER {0}
29+
#define PTHREAD_RWLOCK_INITIALIZER {0}
30+
31+
// glibc extensions
32+
#define PTHREAD_STACK_MIN (1 << 14) // 16KB
33+
#define PTHREAD_RWLOCK_PREFER_READER_NP 0
34+
#define PTHREAD_RWLOCK_PREFER_WRITER_NP 1
35+
#define PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP 2
36+
37+
#endif // LLVM_LIBC_MACROS_PTHREAD_MACRO_H

libc/include/pthread.h.def

+1-33
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,7 @@
1010
#define LLVM_LIBC_PTHREAD_H
1111

1212
#include "__llvm-libc-common.h"
13-
14-
// TODO: move to a pthreads-macros.h file:
15-
// https://github.com/llvm/llvm-project/issues/88997
16-
17-
#define PTHREAD_STACK_MIN (1 << 14) // 16KB
18-
19-
#define PTHREAD_MUTEX_INITIALIZER {0}
20-
#define PTHREAD_RWLOCK_INITIALIZER {}
21-
#define PTHREAD_ONCE_INIT {0}
22-
23-
enum {
24-
PTHREAD_CREATE_JOINABLE = 0x0,
25-
PTHREAD_CREATE_DETACHED = 0x1,
26-
27-
PTHREAD_MUTEX_NORMAL = 0x0,
28-
PTHREAD_MUTEX_ERRORCHECK = 0x1,
29-
PTHREAD_MUTEX_RECURSIVE = 0x2,
30-
PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL,
31-
32-
PTHREAD_PROCESS_PRIVATE = 0x0,
33-
PTHREAD_PROCESS_SHARED = 0x1,
34-
35-
PTHREAD_MUTEX_STALLED = 0x0,
36-
PTHREAD_MUTEX_ROBUST = 0x1,
37-
};
38-
39-
#define PTHREAD_PROCESS_PRIVATE 0
40-
#define PTHREAD_PROCESS_SHARED 1
41-
42-
#define PTHREAD_RWLOCK_PREFER_READER_NP 0
43-
#define PTHREAD_RWLOCK_PREFER_WRITER_NP 1
44-
#define PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP 2
45-
13+
#include "llvm-libc-macros/pthread-macros.h"
4614

4715
%%public_api()
4816

0 commit comments

Comments
 (0)