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 137pw_facade("interrupt_spin_lock") { 138 backend = pw_sync_INTERRUPT_SPIN_LOCK_BACKEND 139 public_configs = [ ":public_include_path" ] 140 public = [ "public/pw_sync/interrupt_spin_lock.h" ] 141 public_deps = [ 142 ":lock_annotations", 143 ":virtual_basic_lockable", 144 "$dir_pw_preprocessor", 145 ] 146 sources = [ "interrupt_spin_lock.cc" ] 147} 148 149pw_facade("thread_notification") { 150 backend = pw_sync_THREAD_NOTIFICATION_BACKEND 151 public_configs = [ ":public_include_path" ] 152 public = [ "public/pw_sync/thread_notification.h" ] 153} 154 155pw_facade("timed_thread_notification") { 156 backend = pw_sync_TIMED_THREAD_NOTIFICATION_BACKEND 157 public_configs = [ ":public_include_path" ] 158 public = [ "public/pw_sync/timed_thread_notification.h" ] 159 public_deps = [ 160 ":thread_notification", 161 "$dir_pw_chrono:system_clock", 162 ] 163} 164 165# This target provides the backend for pw::sync::ThreadNotification based on 166# pw::sync::BinarySemaphore. 167pw_source_set("binary_semaphore_thread_notification_backend") { 168 public_configs = [ 169 ":public_include_path", 170 ":backend_config", 171 ] 172 public = [ 173 "public/pw_sync/backends/binary_semaphore_thread_notification_inline.h", 174 "public/pw_sync/backends/binary_semaphore_thread_notification_native.h", 175 "public_overrides/pw_sync_backend/thread_notification_inline.h", 176 "public_overrides/pw_sync_backend/thread_notification_native.h", 177 ] 178 public_deps = [ 179 ":binary_semaphore", 180 ":thread_notification.facade", 181 ] 182} 183 184# This target provides the backend for pw::sync::TimedThreadNotification based 185# on pw::sync::BinarySemaphore. 186pw_source_set("binary_semaphore_timed_thread_notification_backend") { 187 public_configs = [ 188 ":public_include_path", 189 ":backend_config", 190 ] 191 public = [ 192 "public/pw_sync/backends/binary_semaphore_timed_thread_notification_inline.h", 193 "public_overrides/pw_sync_backend/timed_thread_notification_inline.h", 194 ] 195 public_deps = [ 196 ":binary_semaphore_thread_notification_backend", 197 ":timed_thread_notification.facade", 198 "$dir_pw_chrono:system_clock", 199 ] 200} 201 202pw_source_set("yield_core") { 203 public = [ "public/pw_sync/yield_core.h" ] 204 public_configs = [ ":public_include_path" ] 205} 206 207pw_facade("condition_variable") { 208 backend = pw_sync_CONDITION_VARIABLE_BACKEND 209 public_configs = [ ":public_include_path" ] 210 public = [ "public/pw_sync/condition_variable.h" ] 211 public_deps = [ 212 "$dir_pw_chrono:system_clock", 213 "$dir_pw_sync:mutex", 214 ] 215} 216 217pw_test_group("tests") { 218 tests = [ 219 ":lock_traits_test", 220 ":borrow_test", 221 ":binary_semaphore_facade_test", 222 ":counting_semaphore_facade_test", 223 ":mutex_facade_test", 224 ":timed_mutex_facade_test", 225 ":recursive_mutex_facade_test", 226 ":interrupt_spin_lock_facade_test", 227 ":thread_notification_facade_test", 228 ":timed_thread_notification_facade_test", 229 ":inline_borrowable_test", 230 ] 231} 232 233pw_source_set("lock_testing") { 234 public_configs = [ ":public_include_path" ] 235 public = [ "public/pw_sync/lock_testing.h" ] 236 sources = [ "lock_testing.cc" ] 237 public_deps = [ ":virtual_basic_lockable" ] 238 deps = [ dir_pw_assert ] 239} 240 241pw_source_set("borrow_lockable_tests") { 242 public = [ "pw_sync_private/borrow_lockable_tests.h" ] 243 public_deps = [ 244 ":borrow", 245 ":lock_traits", 246 ] 247} 248 249pw_test("lock_traits_test") { 250 sources = [ "lock_traits_test.cc" ] 251 deps = [ 252 ":lock_testing", 253 ":lock_traits", 254 ] 255} 256 257pw_test("borrow_test") { 258 sources = [ "borrow_test.cc" ] 259 deps = [ 260 ":borrow", 261 ":borrow_lockable_tests", 262 ":lock_testing", 263 ] 264} 265 266pw_test("inline_borrowable_test") { 267 sources = [ "inline_borrowable_test.cc" ] 268 deps = [ 269 ":inline_borrowable", 270 ":interrupt_spin_lock", 271 ":lock_annotations", 272 ":mutex", 273 ] 274} 275 276pw_test("binary_semaphore_facade_test") { 277 enable_if = pw_sync_BINARY_SEMAPHORE_BACKEND != "" 278 sources = [ 279 "binary_semaphore_facade_test.cc", 280 "binary_semaphore_facade_test_c.c", 281 ] 282 deps = [ 283 ":binary_semaphore", 284 "$dir_pw_preprocessor", 285 pw_sync_BINARY_SEMAPHORE_BACKEND, 286 ] 287} 288 289pw_test("counting_semaphore_facade_test") { 290 enable_if = pw_sync_COUNTING_SEMAPHORE_BACKEND != "" 291 sources = [ 292 "counting_semaphore_facade_test.cc", 293 "counting_semaphore_facade_test_c.c", 294 ] 295 deps = [ 296 ":counting_semaphore", 297 "$dir_pw_preprocessor", 298 pw_sync_COUNTING_SEMAPHORE_BACKEND, 299 ] 300} 301 302pw_test("mutex_facade_test") { 303 enable_if = pw_sync_MUTEX_BACKEND != "" 304 sources = [ 305 "mutex_facade_test.cc", 306 "mutex_facade_test_c.c", 307 ] 308 deps = [ 309 ":borrow_lockable_tests", 310 ":mutex", 311 "$dir_pw_preprocessor", 312 pw_sync_MUTEX_BACKEND, 313 ] 314} 315 316pw_test("timed_mutex_facade_test") { 317 enable_if = pw_sync_TIMED_MUTEX_BACKEND != "" 318 sources = [ 319 "timed_mutex_facade_test.cc", 320 "timed_mutex_facade_test_c.c", 321 ] 322 deps = [ 323 ":borrow_lockable_tests", 324 ":timed_mutex", 325 "$dir_pw_preprocessor", 326 pw_sync_TIMED_MUTEX_BACKEND, 327 ] 328} 329 330pw_test("recursive_mutex_facade_test") { 331 enable_if = pw_sync_RECURSIVE_MUTEX_BACKEND != "" 332 sources = [ 333 "recursive_mutex_facade_test.cc", 334 "recursive_mutex_facade_test_c.c", 335 ] 336 deps = [ 337 ":recursive_mutex", 338 "$dir_pw_preprocessor", 339 pw_sync_RECURSIVE_MUTEX_BACKEND, 340 ] 341} 342 343pw_test("interrupt_spin_lock_facade_test") { 344 enable_if = pw_sync_INTERRUPT_SPIN_LOCK_BACKEND != "" 345 sources = [ 346 "interrupt_spin_lock_facade_test.cc", 347 "interrupt_spin_lock_facade_test_c.c", 348 ] 349 deps = [ 350 ":borrow_lockable_tests", 351 ":interrupt_spin_lock", 352 "$dir_pw_preprocessor", 353 pw_sync_INTERRUPT_SPIN_LOCK_BACKEND, 354 ] 355 356 # TODO: https://pwbug.dev/325509758 - Doesn't work on the Pico yet; hangs 357 # indefinitely. 358 if (pw_build_EXECUTABLE_TARGET_TYPE == "pico_executable") { 359 enable_if = false 360 } 361} 362 363pw_test("thread_notification_facade_test") { 364 enable_if = pw_sync_THREAD_NOTIFICATION_BACKEND != "" 365 sources = [ "thread_notification_facade_test.cc" ] 366 deps = [ 367 ":thread_notification", 368 pw_sync_THREAD_NOTIFICATION_BACKEND, 369 ] 370} 371 372pw_test("timed_thread_notification_facade_test") { 373 enable_if = pw_sync_TIMED_THREAD_NOTIFICATION_BACKEND != "" 374 sources = [ "timed_thread_notification_facade_test.cc" ] 375 deps = [ 376 ":timed_thread_notification", 377 pw_sync_TIMED_THREAD_NOTIFICATION_BACKEND, 378 ] 379} 380 381# This needs to be instantiated per platform that provides 382# an implementation of $dir_pw_thread:test_threads and 383# $dir_pw_sync:condition_variable. 384pw_source_set("condition_variable_test") { 385 testonly = pw_unit_test_TESTONLY 386 sources = [ "condition_variable_test.cc" ] 387 deps = [ 388 ":condition_variable", 389 "$dir_pw_containers:vector", 390 "$dir_pw_sync:mutex", 391 "$dir_pw_sync:timed_thread_notification", 392 "$dir_pw_thread:non_portable_test_thread_options", 393 "$dir_pw_thread:sleep", 394 "$dir_pw_thread:thread", 395 "$dir_pw_unit_test", 396 ] 397} 398 399pw_doc_group("docs") { 400 sources = [ 401 "backends.rst", 402 "docs.rst", 403 ] 404} 405