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::Thread with joining 55# joining capability. 56pw_source_set("thread") { 57 public_configs = [ 58 ":public_include_path", 59 ":thread_public_overrides", 60 ] 61 public = [ 62 "public/pw_thread_stl/options.h", 63 "public/pw_thread_stl/thread_inline.h", 64 "public/pw_thread_stl/thread_native.h", 65 "thread_public_overrides/pw_thread_backend/thread_inline.h", 66 "thread_public_overrides/pw_thread_backend/thread_native.h", 67 ] 68 allow_circular_includes_from = [ "$dir_pw_thread:thread.facade" ] 69 deps = [ "$dir_pw_thread:thread.facade" ] 70} 71 72pw_build_assert("check_system_clock_backend") { 73 condition = 74 pw_thread_SLEEP_BACKEND != "$dir_pw_thread_stl:sleep" || 75 pw_chrono_SYSTEM_CLOCK_BACKEND == "" || 76 pw_chrono_SYSTEM_CLOCK_BACKEND == "$dir_pw_chrono_stl:system_clock" 77 message = "The STL pw::this_thread::sleep_{for,until} backend only works " + 78 "with the STL pw::chrono::SystemClock backend " + 79 "(pw_chrono_SYSTEM_CLOCK_BACKEND = " + 80 "\"$dir_pw_chrono_stl:system_clock\")" 81} 82 83config("sleep_public_overrides") { 84 include_dirs = [ "sleep_public_overrides" ] 85 visibility = [ ":*" ] 86} 87 88# This target provides the backend for pw::this_thread::sleep_{for,until}. 89pw_source_set("sleep") { 90 public_configs = [ 91 ":public_include_path", 92 ":sleep_public_overrides", 93 ] 94 public = [ 95 "public/pw_thread_stl/sleep_inline.h", 96 "sleep_public_overrides/pw_thread_backend/sleep_inline.h", 97 ] 98 deps = [ 99 ":check_system_clock_backend", 100 "$dir_pw_chrono:system_clock", 101 "$dir_pw_thread:sleep.facade", 102 ] 103} 104 105config("yield_public_overrides") { 106 include_dirs = [ "yield_public_overrides" ] 107 visibility = [ ":*" ] 108} 109 110# This target provides the backend for pw::this_thread::yield. 111pw_source_set("yield") { 112 public_configs = [ 113 ":public_include_path", 114 ":yield_public_overrides", 115 ] 116 public = [ 117 "public/pw_thread_stl/yield_inline.h", 118 "yield_public_overrides/pw_thread_backend/yield_inline.h", 119 ] 120 deps = [ "$dir_pw_thread:yield.facade" ] 121} 122 123# This target provides a stub backend for pw::this_thread::thread_iteration. 124# Iterating over child threads isn't supported by STL, so this only exists 125# for portability reasons. 126pw_source_set("thread_iteration") { 127 deps = [ 128 "$dir_pw_thread:thread_iteration.facade", 129 dir_pw_status, 130 ] 131 sources = [ "thread_iteration.cc" ] 132} 133 134pw_test_group("tests") { 135 tests = [ ":thread_backend_test" ] 136} 137 138config("test_thread_context_public_overrides") { 139 include_dirs = [ "test_thread_context_public_overrides" ] 140 visibility = [ ":*" ] 141} 142 143pw_source_set("test_thread_context") { 144 public_deps = [ ":thread" ] 145 public_configs = [ 146 ":public_include_path", 147 ":test_thread_context_public_overrides", 148 ] 149 public = [ 150 "public/pw_thread_stl/test_thread_context_native.h", 151 "test_thread_context_public_overrides/pw_thread_backend/test_thread_context_native.h", 152 ] 153 deps = [ "$dir_pw_thread:test_thread_context.facade" ] 154} 155 156pw_source_set("non_portable_test_thread_options") { 157 public_deps = [ "$dir_pw_thread:non_portable_test_thread_options" ] 158 sources = [ "test_threads.cc" ] 159 deps = [ "$dir_pw_thread:thread" ] 160} 161 162pw_test("thread_backend_test") { 163 # TODO: b/317922402 - On Windows, this test can hang indefinitely. Disable on 164 # Windows until we can test with the native Windows SDK libraries for 165 # threading. 166 enable_if = pw_thread_THREAD_BACKEND == "$dir_pw_thread_stl:thread" && 167 pw_thread_SLEEP_BACKEND != "" && current_os != "win" 168 deps = [ 169 ":non_portable_test_thread_options", 170 "$dir_pw_thread:thread_facade_test", 171 ] 172} 173 174pw_doc_group("docs") { 175 sources = [ "docs.rst" ] 176} 177