Skip to content

Commit e837feb

Browse files
Siva Chandra Reddymemfrob
Siva Chandra Reddy
authored and
memfrob
committed
[libc][NFC] Add the platform independent file target only if mutex is available.
The platform independent file implementation is not an entrypoint so it cannot be excluded via the entrypoints.txt file. Hence, we need a special treatment to exclude it from the build. Reviewed By: michaelrj Differential Revision: https://reviews.llvm.org/D121947
1 parent 8dabaa7 commit e837feb

File tree

10 files changed

+60
-30
lines changed

10 files changed

+60
-30
lines changed

libc/src/__support/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ add_header_library(
5454
integer_operations.h
5555
)
5656

57+
# Thread support is used by other support libraries. So, we add the "threads"
58+
# before other directories.
59+
add_subdirectory(threads)
60+
5761
add_subdirectory(File)
5862
add_subdirectory(FPUtil)
5963
add_subdirectory(OSUtil)
60-
add_subdirectory(threads)
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
if(NOT (TARGET libc.src.__support.threads.mutex))
2+
# Not all platforms have a mutex implementation. If mutex is unvailable,
3+
# we just skip everything about files.
4+
return()
5+
endif()
6+
17
add_object_library(
28
file
39
SRCS
410
file.cpp
511
HDRS
612
file.h
713
DEPENDS
8-
libc.src.__support.threads.thread
14+
libc.src.__support.threads.mutex
915
libc.include.errno
1016
libc.src.errno.errno
1117
)
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1+
add_header_library(
2+
mutex_common
3+
HDRS
4+
mutex_common.h
5+
)
6+
17
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS})
28
add_subdirectory(${LIBC_TARGET_OS})
39
endif()
410

5-
add_header_library(
6-
thread
7-
HDRS
8-
mutex.h
9-
DEPENDS
10-
.${LIBC_TARGET_OS}.thread
11-
)
11+
if(TARGET libc.src.__support.threads.${LIBC_TARGET_OS}.mutex)
12+
add_header_library(
13+
mutex
14+
HDRS
15+
mutex.h
16+
DEPENDS
17+
.${LIBC_TARGET_OS}.mutex
18+
)
19+
endif()
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
add_header_library(
2-
thread
2+
mutex
33
HDRS
44
mutex.h
55
DEPENDS
66
libc.include.sys_syscall
77
libc.src.__support.CPP.atomic
88
libc.src.__support.OSUtil.osutil
9+
libc.src.__support.threads.mutex_common
910
)

libc/src/__support/threads/linux/mutex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include "src/__support/CPP/atomic.h"
1313
#include "src/__support/OSUtil/syscall.h" // For syscall functions.
14-
#include "src/__support/threads/mutex.h"
14+
#include "src/__support/threads/mutex_common.h"
1515

1616
#include <linux/futex.h>
1717
#include <stdint.h>

libc/src/__support/threads/mutex.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,6 @@
99
#ifndef LLVM_LIBC_SRC_SUPPORT_THREAD_MUTEX_H
1010
#define LLVM_LIBC_SRC_SUPPORT_THREAD_MUTEX_H
1111

12-
namespace __llvm_libc {
13-
14-
enum class MutexError : int {
15-
NONE,
16-
BUSY,
17-
TIMEOUT,
18-
UNLOCK_WITHOUT_LOCK,
19-
BAD_LOCK_STATE,
20-
};
21-
22-
} // namespace __llvm_libc
23-
2412
// Platform independent code will include this header file which pulls
2513
// the platfrom specific specializations using platform macros.
2614
//
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//===--- Common definitions useful for mutex implementations ----*- 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_SUPPORT_THREAD_MUTEX_COMMON_H
10+
#define LLVM_LIBC_SRC_SUPPORT_THREAD_MUTEX_COMMON_H
11+
12+
namespace __llvm_libc {
13+
14+
enum class MutexError : int {
15+
NONE,
16+
BUSY,
17+
TIMEOUT,
18+
UNLOCK_WITHOUT_LOCK,
19+
BAD_LOCK_STATE,
20+
};
21+
22+
} // namespace __llvm_libc
23+
24+
#endif // LLVM_LIBC_SRC_SUPPORT_THREAD_MUTEX_COMMON_H

libc/src/stdlib/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ add_entrypoint_object(
280280
20 # For constinit of the atexit callback list.
281281
DEPENDS
282282
libc.src.__support.CPP.blockstore
283-
libc.src.__support.threads.thread
283+
libc.src.__support.threads.mutex
284284
)
285285

286286
add_entrypoint_object(

libc/src/threads/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ add_entrypoint_object(
3131
mtx_init.h
3232
DEPENDS
3333
libc.include.threads
34-
libc.src.__support.threads.thread
34+
libc.src.__support.threads.mutex
3535
)
3636

3737
add_entrypoint_object(
@@ -42,7 +42,7 @@ add_entrypoint_object(
4242
mtx_destroy.h
4343
DEPENDS
4444
libc.include.threads
45-
libc.src.__support.threads.thread
45+
libc.src.__support.threads.mutex
4646
)
4747

4848
add_entrypoint_object(
@@ -53,7 +53,7 @@ add_entrypoint_object(
5353
mtx_lock.h
5454
DEPENDS
5555
libc.include.threads
56-
libc.src.__support.threads.thread
56+
libc.src.__support.threads.mutex
5757
)
5858

5959
add_entrypoint_object(
@@ -64,7 +64,7 @@ add_entrypoint_object(
6464
mtx_unlock.h
6565
DEPENDS
6666
libc.include.threads
67-
libc.src.__support.threads.thread
67+
libc.src.__support.threads.mutex
6868
)
6969

7070
add_entrypoint_object(

libc/src/threads/linux/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ add_header_library(
3434
libc.include.threads
3535
libc.src.__support.CPP.atomic
3636
libc.src.__support.OSUtil.osutil
37-
libc.src.__support.threads.thread
37+
libc.src.__support.threads.mutex
3838
)
3939

4040
add_entrypoint_object(
@@ -105,7 +105,7 @@ add_entrypoint_object(
105105
DEPENDS
106106
.threads_utils
107107
libc.include.threads
108-
libc.src.__support.threads.thread
108+
libc.src.__support.threads.mutex
109109
)
110110

111111
add_entrypoint_object(

0 commit comments

Comments
 (0)