summaryrefslogtreecommitdiff
path: root/libc/src/__support/threads/linux/CMakeLists.txt
blob: 39d2c6fef0feddf42844bed98871fa7cabe7d546 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
add_header_library(
  futex_word_type
  HDRS
    futex_word.h
  DEPENDS
    libc.hdr.stdint_proxy
)

if(NOT TARGET libc.src.__support.OSUtil.osutil)
  return()
endif()

add_header_library(
  futex_utils
  HDRS
    futex_utils.h
  DEPENDS
    .futex_word_type
    libc.include.sys_syscall
    libc.src.__support.OSUtil.osutil
    libc.src.__support.CPP.atomic
    libc.src.__support.CPP.limits
    libc.src.__support.CPP.optional
    libc.src.__support.time.linux.abs_timeout
)

set(monotonicity_flags)
if (LIBC_CONF_TIMEOUT_ENSURE_MONOTONICITY)
  set(monotonicity_flags -DLIBC_COPT_TIMEOUT_ENSURE_MONOTONICITY=1)
else()
  set(monotonicity_flags -DLIBC_COPT_TIMEOUT_ENSURE_MONOTONICITY=0)
endif()

add_header_library(
  raw_mutex
  HDRS
    mutex.h
  DEPENDS
    .futex_utils
    libc.src.__support.threads.sleep
    libc.src.__support.time.linux.abs_timeout
    libc.src.__support.time.linux.monotonicity
    libc.src.__support.CPP.optional
    libc.hdr.types.pid_t
  COMPILE_OPTIONS
    -DLIBC_COPT_RAW_MUTEX_DEFAULT_SPIN_COUNT=${LIBC_CONF_RAW_MUTEX_DEFAULT_SPIN_COUNT}
    ${monotonicity_flags}
)

add_header_library(
  rwlock
  HDRS
    rwlock.h
  DEPENDS
    .futex_utils
    .raw_mutex
    libc.src.__support.common
    libc.src.__support.OSUtil.osutil
    libc.src.__support.CPP.limits
    libc.src.__support.threads.identifier
  COMPILE_OPTIONS
    -DLIBC_COPT_RWLOCK_DEFAULT_SPIN_COUNT=${LIBC_CONF_RWLOCK_DEFAULT_SPIN_COUNT}
    ${monotonicity_flags}
)

add_header_library(
  mutex
  HDRS
    mutex.h
  DEPENDS
    .futex_utils
    .raw_mutex
    libc.src.__support.threads.mutex_common
)

add_object_library(
  thread
  SRCS
    thread.cpp
  DEPENDS
    .futex_utils
    libc.config.app_h
    libc.include.sys_syscall
    libc.hdr.fcntl_macros
    libc.src.errno.errno
    libc.src.__support.CPP.atomic
    libc.src.__support.CPP.stringstream
    libc.src.__support.CPP.string_view
    libc.src.__support.common
    libc.src.__support.error_or
    libc.src.__support.threads.thread_common
  COMPILE_OPTIONS
    ${libc_opt_high_flag}
    -fno-omit-frame-pointer # This allows us to sniff out the thread args from
                            # the new thread's stack reliably.
    -Wno-frame-address      # Yes, calling __builtin_return_address with a
                            # value other than 0 is dangerous. We know.
)

add_header_library(
  callonce
  HDRS
    ../callonce.h
    callonce.h
  DEPENDS
    .futex_utils
    libc.src.__support.macros.optimization
)

add_object_library(
  CndVar
  SRCS
    CndVar.cpp
  HDRS
    ../CndVar.h
  DEPENDS
    libc.hdr.stdint_proxy
    libc.include.sys_syscall
    libc.src.__support.OSUtil.osutil
    libc.src.__support.threads.linux.futex_word_type
    libc.src.__support.threads.mutex
    libc.src.__support.threads.linux.raw_mutex
    libc.src.__support.CPP.mutex
)

add_object_library(
  barrier
  HDRS
    barrier.h
  SRCS
    barrier.cpp
  DEPENDS
    libc.src.__support.threads.CndVar
    libc.src.__support.threads.mutex
)