• 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
15import("//build_overrides/pigweed.gni")
16
17import("$dir_pw_build/error.gni")
18import("$dir_pw_build/target_types.gni")
19import("$dir_pw_chrono/backend.gni")
20import("$dir_pw_docgen/docs.gni")
21import("$dir_pw_thread/backend.gni")
22import("$dir_pw_unit_test/test.gni")
23
24config("public_include_path") {
25  include_dirs = [ "public" ]
26  visibility = [ ":*" ]
27}
28
29config("id_public_overrides") {
30  include_dirs = [ "id_public_overrides" ]
31  visibility = [ ":*" ]
32}
33
34# This target provides the backend for pw::Thread::id & pw::this_thread::get_id.
35pw_source_set("id") {
36  public_configs = [
37    ":public_include_path",
38    ":id_public_overrides",
39  ]
40  public = [
41    "id_public_overrides/pw_thread_backend/id_inline.h",
42    "id_public_overrides/pw_thread_backend/id_native.h",
43    "public/pw_thread_stl/id_inline.h",
44    "public/pw_thread_stl/id_native.h",
45  ]
46  deps = [ "$dir_pw_thread:id.facade" ]
47}
48
49config("thread_public_overrides") {
50  include_dirs = [ "thread_public_overrides" ]
51  visibility = [ ":*" ]
52}
53
54# This target provides the backend for pw::Thread with joining capability.
55pw_source_set("thread") {
56  public_configs = [
57    ":public_include_path",
58    ":thread_public_overrides",
59  ]
60  public = [
61    "public/pw_thread_stl/options.h",
62    "public/pw_thread_stl/thread_inline.h",
63    "public/pw_thread_stl/thread_native.h",
64    "thread_public_overrides/pw_thread_backend/thread_inline.h",
65    "thread_public_overrides/pw_thread_backend/thread_native.h",
66  ]
67}
68
69config("thread_creation_public_overrides") {
70  include_dirs = [ "thread_creation_public_overrides" ]
71  visibility = [ ":*" ]
72}
73
74pw_source_set("thread_creation") {
75  public_configs = [ ":thread_creation_public_overrides" ]
76  public = [
77    "thread_creation_public_overrides/pw_thread_backend/context.h",
78    "thread_creation_public_overrides/pw_thread_backend/options.h",
79    "thread_creation_public_overrides/pw_thread_backend/priority.h",
80    "thread_creation_public_overrides/pw_thread_backend/stack.h",
81  ]
82}
83
84pw_build_assert("check_system_clock_backend") {
85  condition =
86      pw_thread_SLEEP_BACKEND != "$dir_pw_thread_stl:sleep" ||
87      pw_chrono_SYSTEM_CLOCK_BACKEND == "" ||
88      pw_chrono_SYSTEM_CLOCK_BACKEND == "$dir_pw_chrono_stl:system_clock"
89  message = "The STL pw::this_thread::sleep_{for,until} backend only works " +
90            "with the STL pw::chrono::SystemClock backend " +
91            "(pw_chrono_SYSTEM_CLOCK_BACKEND = " +
92            "\"$dir_pw_chrono_stl:system_clock\")"
93}
94
95config("sleep_public_overrides") {
96  include_dirs = [ "sleep_public_overrides" ]
97  visibility = [ ":*" ]
98}
99
100# This target provides the backend for pw::this_thread::sleep_{for,until}.
101pw_source_set("sleep") {
102  public_configs = [
103    ":public_include_path",
104    ":sleep_public_overrides",
105  ]
106  public = [
107    "public/pw_thread_stl/sleep_inline.h",
108    "sleep_public_overrides/pw_thread_backend/sleep_inline.h",
109  ]
110  deps = [
111    ":check_system_clock_backend",
112    "$dir_pw_chrono:system_clock",
113    "$dir_pw_thread:sleep.facade",
114  ]
115}
116
117config("yield_public_overrides") {
118  include_dirs = [ "yield_public_overrides" ]
119  visibility = [ ":*" ]
120}
121
122# This target provides the backend for pw::this_thread::yield.
123pw_source_set("yield") {
124  public_configs = [
125    ":public_include_path",
126    ":yield_public_overrides",
127  ]
128  public = [
129    "public/pw_thread_stl/yield_inline.h",
130    "yield_public_overrides/pw_thread_backend/yield_inline.h",
131  ]
132  deps = [ "$dir_pw_thread:yield.facade" ]
133}
134
135# This target provides a stub backend for pw::this_thread::thread_iteration.
136# Iterating over child threads isn't supported by STL, so this only exists
137# for portability reasons.
138pw_source_set("thread_iteration") {
139  deps = [
140    "$dir_pw_thread:thread_iteration.facade",
141    dir_pw_status,
142  ]
143  sources = [ "thread_iteration.cc" ]
144}
145
146pw_test_group("tests") {
147  tests = [ ":thread_backend_test" ]
148}
149
150config("test_thread_context_public_overrides") {
151  include_dirs = [ "test_thread_context_public_overrides" ]
152  visibility = [ ":*" ]
153}
154
155pw_source_set("test_thread_context") {
156  public_deps = [ ":thread" ]
157  public_configs = [
158    ":public_include_path",
159    ":test_thread_context_public_overrides",
160  ]
161  public = [
162    "public/pw_thread_stl/test_thread_context_native.h",
163    "test_thread_context_public_overrides/pw_thread_backend/test_thread_context_native.h",
164  ]
165  deps = [ "$dir_pw_thread:test_thread_context.facade" ]
166}
167
168pw_source_set("non_portable_test_thread_options") {
169  public_deps = [ "$dir_pw_thread:non_portable_test_thread_options" ]
170  sources = [ "test_threads.cc" ]
171  deps = [ "$dir_pw_thread:thread" ]
172}
173
174pw_test("thread_backend_test") {
175  # TODO: b/317922402 - On Windows, this test can hang indefinitely. Disable on
176  # Windows until we can test with the native Windows SDK libraries for
177  # threading.
178  enable_if = pw_thread_THREAD_BACKEND == "$dir_pw_thread_stl:thread" &&
179              pw_thread_SLEEP_BACKEND != "" && current_os != "win"
180  deps = [
181    ":non_portable_test_thread_options",
182    "$dir_pw_thread:thread_facade_test",
183  ]
184}
185
186pw_doc_group("docs") {
187  sources = [ "docs.rst" ]
188}
189