1# Copyright 2021 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/facade.gni") 18import("$dir_pw_build/target_types.gni") 19import("$dir_pw_chrono/backend.gni") 20import("$dir_pw_docgen/docs.gni") 21import("$dir_pw_unit_test/test.gni") 22import("backend.gni") 23 24config("public_include_path") { 25 include_dirs = [ "public" ] 26 visibility = [ ":*" ] 27} 28 29config("backend_config") { 30 include_dirs = [ "public_overrides" ] 31 visibility = [ ":*" ] 32} 33 34pw_facade("binary_semaphore") { 35 backend = pw_sync_BINARY_SEMAPHORE_BACKEND 36 public_configs = [ ":public_include_path" ] 37 public = [ "public/pw_sync/binary_semaphore.h" ] 38 public_deps = [ 39 "$dir_pw_chrono:system_clock", 40 "$dir_pw_preprocessor", 41 ] 42 sources = [ "binary_semaphore.cc" ] 43} 44 45pw_facade("counting_semaphore") { 46 backend = pw_sync_COUNTING_SEMAPHORE_BACKEND 47 public_configs = [ ":public_include_path" ] 48 public = [ "public/pw_sync/counting_semaphore.h" ] 49 public_deps = [ 50 "$dir_pw_chrono:system_clock", 51 "$dir_pw_preprocessor", 52 ] 53 sources = [ "counting_semaphore.cc" ] 54} 55 56pw_source_set("lock_annotations") { 57 public_configs = [ ":public_include_path" ] 58 public = [ "public/pw_sync/lock_annotations.h" ] 59 public_deps = [ "$dir_pw_preprocessor" ] 60} 61 62pw_source_set("lock_traits") { 63 public_configs = [ ":public_include_path" ] 64 public = [ "public/pw_sync/lock_traits.h" ] 65} 66 67pw_source_set("borrow") { 68 public_configs = [ ":public_include_path" ] 69 public = [ "public/pw_sync/borrow.h" ] 70 public_deps = [ 71 ":lock_annotations", 72 ":lock_traits", 73 ":virtual_basic_lockable", 74 dir_pw_assert, 75 ] 76} 77 78pw_source_set("inline_borrowable") { 79 public = [ 80 "public/pw_sync/inline_borrowable.h", 81 "public/pw_sync/internal/borrowable_storage.h", 82 ] 83 public_deps = [ 84 ":borrow", 85 ":mutex", 86 ":virtual_basic_lockable", 87 ] 88 public_configs = [ ":public_include_path" ] 89} 90 91pw_source_set("virtual_basic_lockable") { 92 public_configs = [ ":public_include_path" ] 93 public = [ "public/pw_sync/virtual_basic_lockable.h" ] 94 public_deps = [ 95 ":lock_annotations", 96 dir_pw_polyfill, 97 ] 98} 99 100pw_facade("mutex") { 101 backend = pw_sync_MUTEX_BACKEND 102 public_configs = [ ":public_include_path" ] 103 public = [ "public/pw_sync/mutex.h" ] 104 public_deps = [ 105 ":lock_annotations", 106 ":virtual_basic_lockable", 107 "$dir_pw_preprocessor", 108 ] 109 sources = [ "mutex.cc" ] 110} 111 112pw_facade("timed_mutex") { 113 backend = pw_sync_TIMED_MUTEX_BACKEND 114 public_configs = [ ":public_include_path" ] 115 public = [ "public/pw_sync/timed_mutex.h" ] 116 public_deps = [ 117 ":mutex", 118 ":virtual_basic_lockable", 119 "$dir_pw_chrono:system_clock", 120 "$dir_pw_preprocessor", 121 ] 122 sources = [ "timed_mutex.cc" ] 123} 124 125pw_facade("recursive_mutex") { 126 backend = pw_sync_RECURSIVE_MUTEX_BACKEND 127 public_configs = [ ":public_include_path" ] 128 public = [ "public/pw_sync/recursive_mutex.h" ] 129 public_deps = [ 130 ":lock_annotations", 131 "$dir_pw_preprocessor", 132 ] 133 sources = [ "recursive_mutex.cc" ] 134 visibility = [ 135 ":*", 136 "$dir_pw_sync_baremetal/*", 137 "$dir_pw_sync_stl/*", 138 ] 139} 140 141pw_facade("interrupt_spin_lock") { 142 backend = pw_sync_INTERRUPT_SPIN_LOCK_BACKEND 143 public_configs = [ ":public_include_path" ] 144 public = [ "public/pw_sync/interrupt_spin_lock.h" ] 145 public_deps = [ 146 ":lock_annotations", 147 ":virtual_basic_lockable", 148 "$dir_pw_preprocessor", 149 ] 150 sources = [ "interrupt_spin_lock.cc" ] 151} 152 153pw_facade("thread_notification") { 154 backend = pw_sync_THREAD_NOTIFICATION_BACKEND 155 public_configs = [ ":public_include_path" ] 156 public = [ "public/pw_sync/thread_notification.h" ] 157} 158 159pw_facade("timed_thread_notification") { 160 backend = pw_sync_TIMED_THREAD_NOTIFICATION_BACKEND 161 public_configs = [ ":public_include_path" ] 162 public = [ "public/pw_sync/timed_thread_notification.h" ] 163 public_deps = [ 164 ":thread_notification", 165 "$dir_pw_chrono:system_clock", 166 ] 167} 168 169# This target provides the backend for pw::sync::ThreadNotification based on 170# pw::sync::BinarySemaphore. 171pw_source_set("binary_semaphore_thread_notification_backend") { 172 public_configs = [ 173 ":public_include_path", 174 ":backend_config", 175 ] 176 public = [ 177 "public/pw_sync/backends/binary_semaphore_thread_notification_inline.h", 178 "public/pw_sync/backends/binary_semaphore_thread_notification_native.h", 179 "public_overrides/pw_sync_backend/thread_notification_inline.h", 180 "public_overrides/pw_sync_backend/thread_notification_native.h", 181 ] 182 public_deps = [ 183 ":binary_semaphore", 184 ":thread_notification.facade", 185 ] 186} 187 188# This target provides the backend for pw::sync::TimedThreadNotification based 189# on pw::sync::BinarySemaphore. 190pw_source_set("binary_semaphore_timed_thread_notification_backend") { 191 public_configs = [ 192 ":public_include_path", 193 ":backend_config", 194 ] 195 public = [ 196 "public/pw_sync/backends/binary_semaphore_timed_thread_notification_inline.h", 197 "public_overrides/pw_sync_backend/timed_thread_notification_inline.h", 198 ] 199 public_deps = [ 200 ":binary_semaphore_thread_notification_backend", 201 ":timed_thread_notification.facade", 202 "$dir_pw_chrono:system_clock", 203 ] 204} 205 206pw_source_set("yield_core") { 207 public = [ "public/pw_sync/yield_core.h" ] 208 public_configs = [ ":public_include_path" ] 209} 210 211pw_facade("condition_variable") { 212 backend = pw_sync_CONDITION_VARIABLE_BACKEND 213 public_configs = [ ":public_include_path" ] 214 public = [ "public/pw_sync/condition_variable.h" ] 215 public_deps = [ 216 "$dir_pw_chrono:system_clock", 217 "$dir_pw_sync:mutex", 218 ] 219} 220 221pw_test_group("tests") { 222 tests = [ 223 ":lock_traits_test", 224 ":borrow_test", 225 ":binary_semaphore_facade_test", 226 ":counting_semaphore_facade_test", 227 ":mutex_facade_test", 228 ":timed_mutex_facade_test", 229 ":recursive_mutex_facade_test", 230 ":interrupt_spin_lock_facade_test", 231 ":thread_notification_facade_test", 232 ":timed_thread_notification_facade_test", 233 ":inline_borrowable_test", 234 ] 235} 236 237pw_source_set("lock_testing") { 238 public_configs = [ ":public_include_path" ] 239 public = [ "public/pw_sync/lock_testing.h" ] 240 sources = [ "lock_testing.cc" ] 241 public_deps = [ ":virtual_basic_lockable" ] 242 deps = [ dir_pw_assert ] 243} 244 245pw_source_set("borrow_lockable_tests") { 246 public = [ "pw_sync_private/borrow_lockable_tests.h" ] 247 public_deps = [ 248 ":borrow", 249 ":lock_traits", 250 ] 251} 252 253pw_test("lock_traits_test") { 254 sources = [ "lock_traits_test.cc" ] 255 deps = [ 256 ":lock_testing", 257 ":lock_traits", 258 ] 259} 260 261pw_test("borrow_test") { 262 sources = [ "borrow_test.cc" ] 263 deps = [ 264 ":borrow", 265 ":borrow_lockable_tests", 266 ":lock_testing", 267 ] 268} 269 270pw_test("inline_borrowable_test") { 271 sources = [ "inline_borrowable_test.cc" ] 272 deps = [ 273 ":inline_borrowable", 274 ":interrupt_spin_lock", 275 ":lock_annotations", 276 ":mutex", 277 ] 278} 279 280pw_test("binary_semaphore_facade_test") { 281 enable_if = pw_sync_BINARY_SEMAPHORE_BACKEND != "" 282 sources = [ 283 "binary_semaphore_facade_test.cc", 284 "binary_semaphore_facade_test_c.c", 285 ] 286 deps = [ 287 ":binary_semaphore", 288 "$dir_pw_preprocessor", 289 pw_sync_BINARY_SEMAPHORE_BACKEND, 290 ] 291} 292 293pw_test("counting_semaphore_facade_test") { 294 enable_if = pw_sync_COUNTING_SEMAPHORE_BACKEND != "" 295 sources = [ 296 "counting_semaphore_facade_test.cc", 297 "counting_semaphore_facade_test_c.c", 298 ] 299 deps = [ 300 ":counting_semaphore", 301 "$dir_pw_preprocessor", 302 pw_sync_COUNTING_SEMAPHORE_BACKEND, 303 ] 304} 305 306pw_test("mutex_facade_test") { 307 enable_if = pw_sync_MUTEX_BACKEND != "" 308 sources = [ 309 "mutex_facade_test.cc", 310 "mutex_facade_test_c.c", 311 ] 312 deps = [ 313 ":borrow_lockable_tests", 314 ":mutex", 315 "$dir_pw_preprocessor", 316 pw_sync_MUTEX_BACKEND, 317 ] 318} 319 320pw_test("timed_mutex_facade_test") { 321 enable_if = pw_sync_TIMED_MUTEX_BACKEND != "" 322 sources = [ 323 "timed_mutex_facade_test.cc", 324 "timed_mutex_facade_test_c.c", 325 ] 326 deps = [ 327 ":borrow_lockable_tests", 328 ":timed_mutex", 329 "$dir_pw_preprocessor", 330 pw_sync_TIMED_MUTEX_BACKEND, 331 ] 332} 333 334pw_test("recursive_mutex_facade_test") { 335 enable_if = pw_sync_RECURSIVE_MUTEX_BACKEND != "" 336 sources = [ 337 "recursive_mutex_facade_test.cc", 338 "recursive_mutex_facade_test_c.c", 339 ] 340 deps = [ 341 ":recursive_mutex", 342 "$dir_pw_preprocessor", 343 pw_sync_RECURSIVE_MUTEX_BACKEND, 344 ] 345} 346 347pw_test("interrupt_spin_lock_facade_test") { 348 enable_if = pw_sync_INTERRUPT_SPIN_LOCK_BACKEND != "" 349 sources = [ 350 "interrupt_spin_lock_facade_test.cc", 351 "interrupt_spin_lock_facade_test_c.c", 352 ] 353 deps = [ 354 ":borrow_lockable_tests", 355 ":interrupt_spin_lock", 356 "$dir_pw_preprocessor", 357 pw_sync_INTERRUPT_SPIN_LOCK_BACKEND, 358 ] 359 360 # TODO: https://pwbug.dev/325509758 - Doesn't work on the Pico yet; hangs 361 # indefinitely. 362 if (pw_build_EXECUTABLE_TARGET_TYPE == "pico_executable") { 363 enable_if = false 364 } 365} 366 367pw_test("thread_notification_facade_test") { 368 enable_if = pw_sync_THREAD_NOTIFICATION_BACKEND != "" 369 sources = [ "thread_notification_facade_test.cc" ] 370 deps = [ 371 ":thread_notification", 372 pw_sync_THREAD_NOTIFICATION_BACKEND, 373 ] 374} 375 376pw_test("timed_thread_notification_facade_test") { 377 enable_if = pw_sync_TIMED_THREAD_NOTIFICATION_BACKEND != "" 378 sources = [ "timed_thread_notification_facade_test.cc" ] 379 deps = [ 380 ":timed_thread_notification", 381 pw_sync_TIMED_THREAD_NOTIFICATION_BACKEND, 382 ] 383} 384 385# This needs to be instantiated per platform that provides 386# an implementation of $dir_pw_thread:test_threads and 387# $dir_pw_sync:condition_variable. 388pw_source_set("condition_variable_test") { 389 testonly = pw_unit_test_TESTONLY 390 sources = [ "condition_variable_test.cc" ] 391 deps = [ 392 ":condition_variable", 393 "$dir_pw_containers:vector", 394 "$dir_pw_sync:mutex", 395 "$dir_pw_sync:timed_thread_notification", 396 "$dir_pw_thread:non_portable_test_thread_options", 397 "$dir_pw_thread:sleep", 398 "$dir_pw_thread:thread", 399 "$dir_pw_unit_test", 400 ] 401} 402 403pw_doc_group("docs") { 404 sources = [ 405 "backends.rst", 406 "docs.rst", 407 ] 408} 409