• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2020 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14
15load("@rules_python//python:proto.bzl", "py_proto_library")
16load(
17    "//pw_build:pigweed.bzl",
18    "pw_cc_test",
19    "pw_facade",
20)
21load("//pw_protobuf_compiler:pw_proto_library.bzl", "pw_proto_library")
22
23package(default_visibility = ["//visibility:public"])
24
25licenses(["notice"])
26
27pw_facade(
28    name = "id",
29    hdrs = [
30        "public/pw_thread/id.h",
31    ],
32    backend = ":id_backend",
33    includes = ["public"],
34)
35
36label_flag(
37    name = "id_backend",
38    build_setting_default = ":id_backend_multiplexer",
39)
40
41cc_library(
42    name = "id_backend_multiplexer",
43    visibility = ["@pigweed//targets:__pkg__"],
44    deps = select({
45        "//pw_build/constraints/rtos:embos": ["//pw_thread_embos:id"],
46        "//pw_build/constraints/rtos:freertos": ["//pw_thread_freertos:id"],
47        "//pw_build/constraints/rtos:threadx": ["//pw_thread_threadx:id"],
48        "//conditions:default": ["//pw_thread_stl:id"],
49    }),
50)
51
52cc_library(
53    name = "config",
54    hdrs = ["public/pw_thread/config.h"],
55    includes = ["public"],
56    deps = [":config_override"],
57)
58
59label_flag(
60    name = "config_override",
61    build_setting_default = "//pw_build:default_module_config",
62)
63
64cc_library(
65    name = "thread_info",
66    hdrs = ["public/pw_thread/thread_info.h"],
67    includes = ["public"],
68    deps = ["//pw_span"],
69)
70
71pw_facade(
72    name = "thread_iteration",
73    hdrs = [
74        "public/pw_thread/thread_iteration.h",
75    ],
76    backend = ":iteration_backend",
77    includes = ["public"],
78    deps = [
79        ":thread_info",
80        "//pw_function",
81        "//pw_status",
82    ],
83)
84
85label_flag(
86    name = "iteration_backend",
87    build_setting_default = ":iteration_backend_multiplexer",
88)
89
90cc_library(
91    name = "iteration_backend_multiplexer",
92    visibility = ["@pigweed//targets:__pkg__"],
93    deps = select({
94        "//pw_build/constraints/rtos:embos": ["//pw_thread_embos:thread_iteration"],
95        "//pw_build/constraints/rtos:freertos": ["//pw_thread_freertos:thread_iteration"],
96        "//pw_build/constraints/rtos:threadx": ["//pw_thread_threadx:thread_iteration"],
97        "//conditions:default": ["//pw_thread_stl:thread_iteration"],
98    }),
99)
100
101pw_facade(
102    name = "sleep",
103    srcs = [
104        "sleep.cc",
105    ],
106    hdrs = [
107        "public/pw_thread/sleep.h",
108    ],
109    backend = ":sleep_backend",
110    implementation_deps = [
111        ":id",
112    ],
113    includes = ["public"],
114    deps = [
115        "//pw_chrono:system_clock",
116        "//pw_preprocessor",
117    ],
118)
119
120label_flag(
121    name = "sleep_backend",
122    build_setting_default = ":sleep_backend_multiplexer",
123)
124
125cc_library(
126    name = "sleep_backend_multiplexer",
127    visibility = ["@pigweed//targets:__pkg__"],
128    deps = select({
129        "//pw_build/constraints/rtos:embos": ["//pw_thread_embos:sleep"],
130        "//pw_build/constraints/rtos:freertos": ["//pw_thread_freertos:sleep"],
131        "//pw_build/constraints/rtos:threadx": ["//pw_thread_threadx:sleep"],
132        "//conditions:default": ["//pw_thread_stl:sleep"],
133    }),
134)
135
136pw_facade(
137    name = "thread",
138    srcs = [
139        "public/pw_thread/config.h",
140        "thread.cc",
141    ],
142    hdrs = [
143        "public/pw_thread/detached_thread.h",
144        "public/pw_thread/thread.h",
145    ],
146    backend = ":thread_backend",
147    includes = ["public"],
148    deps = [
149        ":id",
150        ":thread_core",
151        "//pw_function",
152    ],
153)
154
155label_flag(
156    name = "thread_backend",
157    build_setting_default = ":thread_backend_multiplexer",
158)
159
160cc_library(
161    name = "thread_backend_multiplexer",
162    visibility = ["@pigweed//targets:__pkg__"],
163    deps = select({
164        "//pw_build/constraints/rtos:embos": ["//pw_thread_embos:thread"],
165        "//pw_build/constraints/rtos:freertos": ["//pw_thread_freertos:thread"],
166        "//pw_build/constraints/rtos:threadx": ["//pw_thread_threadx:thread"],
167        "//conditions:default": ["//pw_thread_stl:thread"],
168    }),
169)
170
171cc_library(
172    name = "deprecated_or_new_thread_function",
173    hdrs = ["public/pw_thread/deprecated_or_new_thread_function.h"],
174    includes = ["public"],
175    deps = [
176        "//pw_function",
177    ],
178)
179
180pw_cc_test(
181    name = "deprecated_or_new_thread_function_test",
182    srcs = [
183        "deprecated_or_new_thread_function_test.cc",
184    ],
185    deps = [
186        ":deprecated_or_new_thread_function",
187    ],
188)
189
190cc_library(
191    name = "thread_core",
192    hdrs = [
193        "public/pw_thread/thread_core.h",
194    ],
195    includes = ["public"],
196    deps = [
197        "//pw_log",
198        "//pw_status",
199    ],
200)
201
202cc_library(
203    name = "thread_snapshot_service",
204    srcs = [
205        "pw_thread_private/thread_snapshot_service.h",
206        "thread_snapshot_service.cc",
207    ],
208    hdrs = ["public/pw_thread/thread_snapshot_service.h"],
209    includes = ["public"],
210    deps = [
211        "//pw_protobuf",
212        "//pw_rpc/raw:server_api",
213        "//pw_span",
214        "//pw_status",
215        ":config",
216        ":thread_cc.pwpb",
217        ":thread_info",
218        ":thread_iteration",
219        ":thread_snapshot_service_cc.pwpb",
220        ":thread_snapshot_service_cc.raw_rpc",
221        # TODO(amontanez): This should depend on FreeRTOS but our third parties
222        # currently do not have Bazel support.
223    ],
224)
225
226cc_library(
227    name = "test_thread_context_backend_multiplexer",
228    visibility = ["@pigweed//targets:__pkg__"],
229    deps = select({
230        "//conditions:default": ["//pw_thread_stl:test_thread_context"],
231    }),
232)
233
234pw_facade(
235    name = "test_thread_context",
236    hdrs = [
237        "public/pw_thread/test_thread_context.h",
238    ],
239    backend = ":test_thread_context_backend",
240    includes = ["public"],
241)
242
243label_flag(
244    name = "test_thread_context_backend",
245    build_setting_default = ":test_thread_context_backend_multiplexer",
246)
247
248pw_facade(
249    name = "yield",
250    srcs = [
251        "yield.cc",
252    ],
253    hdrs = [
254        "public/pw_thread/yield.h",
255    ],
256    backend = ":yield_backend",
257    implementation_deps = [
258        ":id",
259    ],
260    includes = ["public"],
261    deps = [
262        "//pw_preprocessor",
263    ],
264)
265
266label_flag(
267    name = "yield_backend",
268    build_setting_default = ":yield_backend_multiplexer",
269)
270
271cc_library(
272    name = "yield_backend_multiplexer",
273    visibility = ["@pigweed//targets:__pkg__"],
274    deps = select({
275        "//pw_build/constraints/rtos:embos": ["//pw_thread_embos:yield"],
276        "//pw_build/constraints/rtos:freertos": ["//pw_thread_freertos:yield"],
277        "//pw_build/constraints/rtos:threadx": ["//pw_thread_threadx:yield"],
278        "//conditions:default": ["//pw_thread_stl:yield"],
279    }),
280)
281
282cc_library(
283    name = "snapshot",
284    srcs = [
285        "snapshot.cc",
286    ],
287    hdrs = [
288        "public/pw_thread/snapshot.h",
289    ],
290    deps = [
291        ":thread",
292        ":thread_cc.pwpb",
293        "//pw_bytes",
294        "//pw_function",
295        "//pw_log",
296        "//pw_protobuf",
297        "//pw_status",
298    ],
299)
300
301cc_library(
302    name = "non_portable_test_thread_options",
303    hdrs = [
304        "public/pw_thread/non_portable_test_thread_options.h",
305    ],
306    deps = [
307        ":thread",
308    ],
309)
310
311# To instantiate this as a pw_cc_test, depend on this pw_cc_library and the
312# pw_cc_library which implements the backend for non_portable_test_thread_options. See
313# //pw_thread_stl:thread_backend_test as an example.
314cc_library(
315    name = "thread_facade_test",
316    testonly = True,
317    srcs = [
318        "thread_facade_test.cc",
319    ],
320    deps = [
321        ":id",
322        ":non_portable_test_thread_options",
323        ":thread",
324        "//pw_chrono:system_clock",
325        "//pw_sync:binary_semaphore",
326        "//pw_unit_test",
327    ],
328    alwayslink = True,
329)
330
331pw_cc_test(
332    name = "test_thread_context_facade_test",
333    srcs = [
334        "test_thread_context_facade_test.cc",
335    ],
336    # TODO: b/317922402 - On Windows, this test can easily hang indefinitely.
337    # Disable on Windows until we can test with the native Windows SDK libraries
338    # for threading.
339    target_compatible_with = select({
340        "@platforms//os:windows": ["@platforms//:incompatible"],
341        "//conditions:default": [],
342    }),
343    deps = [
344        ":test_thread_context",
345        ":thread",
346        "//pw_sync:binary_semaphore",
347        "//pw_unit_test",
348    ],
349)
350
351pw_cc_test(
352    name = "id_facade_test",
353    srcs = [
354        "id_facade_test.cc",
355    ],
356    deps = [
357        ":id",
358        "//pw_unit_test",
359    ],
360)
361
362pw_cc_test(
363    name = "sleep_facade_test",
364    srcs = [
365        "sleep_facade_test.cc",
366        "sleep_facade_test_c.c",
367    ],
368    deps = [
369        ":id",
370        ":sleep",
371        "//pw_chrono:system_clock",
372        "//pw_preprocessor",
373        "//pw_unit_test",
374    ],
375)
376
377pw_cc_test(
378    name = "thread_info_test",
379    srcs = [
380        "thread_info_test.cc",
381    ],
382    deps = [
383        ":thread_info",
384        "//pw_span",
385    ],
386)
387
388pw_cc_test(
389    name = "thread_snapshot_service_test",
390    srcs = [
391        "pw_thread_private/thread_snapshot_service.h",
392        "thread_snapshot_service_test.cc",
393    ],
394    # TODO: https://pwbug.dev/342662853 - This test fails under ASAN.
395    tags = ["noasan"],
396    deps = [
397        ":thread_cc.pwpb",
398        ":thread_info",
399        ":thread_iteration",
400        ":thread_snapshot_service",
401        ":thread_snapshot_service_cc.pwpb",
402        "//pw_protobuf",
403        "//pw_span",
404        "//pw_sync:thread_notification",
405    ],
406)
407
408pw_cc_test(
409    name = "yield_facade_test",
410    srcs = [
411        "yield_facade_test.cc",
412        "yield_facade_test_c.c",
413    ],
414    deps = [
415        ":id",
416        ":yield",
417        "//pw_preprocessor",
418        "//pw_unit_test",
419    ],
420)
421
422proto_library(
423    name = "thread_proto",
424    srcs = ["pw_thread_protos/thread.proto"],
425    strip_import_prefix = "/pw_thread",
426    deps = [
427        "//pw_tokenizer:tokenizer_proto",
428    ],
429)
430
431py_proto_library(
432    name = "thread_proto_py_pb2",
433    deps = [":thread_proto"],
434)
435
436proto_library(
437    name = "thread_snapshot_service_proto",
438    srcs = ["pw_thread_protos/thread_snapshot_service.proto"],
439    strip_import_prefix = "/pw_thread",
440    deps = [
441        ":thread_proto",
442    ],
443)
444
445pw_proto_library(
446    name = "thread_snapshot_service_cc",
447    deps = [":thread_snapshot_service_proto"],
448)
449
450py_proto_library(
451    name = "thread_snapshot_service_py_pb2",
452    deps = [":thread_snapshot_service_proto"],
453)
454
455pw_proto_library(
456    name = "thread_cc",
457    deps = [":thread_proto"],
458)
459