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(
16    "//pw_build:pigweed.bzl",
17    "pw_cc_library",
18    "pw_cc_test",
19)
20
21package(default_visibility = ["//visibility:public"])
22
23licenses(["notice"])  # Apache License 2.0
24
25# TODO(pwbug/101): Need to add support for facades/backends to Bazel.
26PW_SYNC_BINARY_SEMAPHORE_BACKEND = "//pw_sync_stl:binary_semaphore"
27PW_SYNC_COUNTING_SEMAPHORE_BACKEND = "//pw_sync_stl:counting_semaphore"
28PW_SYNC_MUTEX_BACKEND = "//pw_sync_stl:mutex"
29PW_SYNC_TIMED_MUTEX_BACKEND = "//pw_sync_stl:timed_mutex"
30PW_SYNC_INTERRUPT_SPIN_LOCK_BACKEND = "//pw_sync_stl:interrupt_spin_lock"
31
32pw_cc_library(
33    name = "binary_semaphore_facade",
34    hdrs = [
35        "public/pw_sync/binary_semaphore.h",
36    ],
37    includes = ["public"],
38    srcs = [
39        "binary_semaphore.cc"
40    ],
41    deps = [
42        PW_SYNC_BINARY_SEMAPHORE_BACKEND + "_headers",
43        "//pw_chrono:system_clock",
44        "//pw_preprocessor",
45    ],
46)
47
48pw_cc_library(
49    name = "binary_semaphore",
50    deps = [
51        ":binary_semaphore_facade",
52        PW_SYNC_BINARY_SEMAPHORE_BACKEND + "_headers",
53    ],
54)
55
56pw_cc_library(
57    name = "binary_semaphore_backend",
58    deps = [
59       PW_SYNC_BINARY_SEMAPHORE_BACKEND,
60    ],
61)
62
63pw_cc_library(
64    name = "counting_semaphore_facade",
65    hdrs = [
66        "public/pw_sync/counting_semaphore.h",
67    ],
68    includes = ["public"],
69    srcs = [
70        "counting_semaphore.cc"
71    ],
72    deps = [
73        PW_SYNC_COUNTING_SEMAPHORE_BACKEND + "_headers",
74        "//pw_chrono:system_clock",
75        "//pw_preprocessor",
76    ],
77)
78
79pw_cc_library(
80    name = "counting_semaphore",
81    deps = [
82        ":counting_semaphore_facade",
83        PW_SYNC_COUNTING_SEMAPHORE_BACKEND + "_headers",
84    ],
85)
86
87pw_cc_library(
88    name = "counting_semaphore_backend",
89    deps = [
90       PW_SYNC_COUNTING_SEMAPHORE_BACKEND,
91    ],
92)
93
94pw_cc_library(
95    name = "lock_annotations",
96    hdrs = [
97        "public/pw_sync/lock_annotations.h",
98    ],
99    includes = ["public"],
100    deps = [
101        "//pw_preprocessor",
102    ],
103)
104
105pw_cc_library(
106    name = "mutex_facade",
107    hdrs = [
108        "public/pw_sync/mutex.h",
109    ],
110    includes = ["public"],
111    srcs = [
112        "mutex.cc"
113    ],
114    deps = [
115		    ":lock_annotations",
116        "//pw_preprocessor",
117        PW_SYNC_MUTEX_BACKEND + "_headers",
118    ],
119)
120
121pw_cc_library(
122    name = "mutex",
123    deps = [
124        ":mutex_facade",
125        PW_SYNC_MUTEX_BACKEND + "_headers",
126    ],
127)
128
129pw_cc_library(
130    name = "mutex_backend",
131    deps = [
132       PW_SYNC_MUTEX_BACKEND,
133    ],
134)
135
136pw_cc_library(
137    name = "timed_mutex_facade",
138    hdrs = [
139        "public/pw_sync/timed_mutex.h",
140    ],
141    includes = ["public"],
142    srcs = [
143        "timed_mutex.cc"
144    ],
145    deps = [
146		    ":lock_annotations",
147        ":mutex_facade",
148        "//pw_chrono:system_clock",
149        "//pw_preprocessor",
150        PW_SYNC_TIMED_MUTEX_BACKEND + "_headers",
151    ],
152)
153
154pw_cc_library(
155    name = "timed_mutex",
156    deps = [
157        ":timed_mutex_facade",
158        PW_SYNC_TIMED_MUTEX_BACKEND + "_headers",
159    ],
160)
161
162pw_cc_library(
163    name = "timed_mutex_backend",
164    deps = [
165       PW_SYNC_TIMED_MUTEX_BACKEND,
166    ],
167)
168
169pw_cc_library(
170    name = "interrupt_spin_lock_facade",
171    hdrs = [
172        "public/pw_sync/interrupt_spin_lock.h",
173    ],
174    includes = ["public"],
175    srcs = [
176        "interrupt_spin_lock.cc"
177    ],
178    deps = [
179		    ":lock_annotations",
180        "//pw_preprocessor",
181        PW_SYNC_INTERRUPT_SPIN_LOCK_BACKEND + "_headers",
182    ],
183)
184
185pw_cc_library(
186    name = "interrupt_spin_lock",
187    deps = [
188        ":interrupt_spin_lock_facade",
189        PW_SYNC_INTERRUPT_SPIN_LOCK_BACKEND + "_headers",
190    ],
191)
192
193pw_cc_library(
194    name = "interrupt_spin_lock_backend",
195    deps = [
196       PW_SYNC_INTERRUPT_SPIN_LOCK_BACKEND,
197    ],
198)
199
200pw_cc_library(
201    name = "yield_core",
202    hdrs = [
203        "public/pw_sync/yield_core.h",
204    ],
205    includes = ["public"],
206)
207
208pw_cc_test(
209    name = "binary_semaphore_facade_test",
210    srcs = [
211        "binary_semaphore_facade_test.cc",
212        "binary_semaphore_facade_test_c.c",
213    ],
214    deps = [
215        ":binary_semaphore",
216        "//pw_preprocessor",
217        "//pw_unit_test",
218    ],
219)
220
221pw_cc_test(
222    name = "counting_semaphore_facade_test",
223    srcs = [
224        "counting_semaphore_facade_test.cc",
225        "counting_semaphore_facade_test_c.c",
226    ],
227    deps = [
228        ":counting_semaphore",
229        "//pw_preprocessor",
230        "//pw_unit_test",
231    ],
232)
233
234pw_cc_test(
235    name = "mutex_facade_test",
236    srcs = [
237        "mutex_facade_test.cc",
238        "mutex_facade_test_c.c",
239    ],
240    deps = [
241        ":mutex",
242        "//pw_preprocessor",
243        "//pw_unit_test",
244    ],
245)
246
247pw_cc_test(
248    name = "timed_mutex_facade_test",
249    srcs = [
250        "timed_mutex_facade_test.cc",
251        "timed_mutex_facade_test_c.c",
252    ],
253    deps = [
254        ":timed_mutex",
255        "//pw_preprocessor",
256        "//pw_unit_test",
257    ],
258)
259
260pw_cc_test(
261    name = "interrupt_spin_lock_facade_test",
262    srcs = [
263        "interrupt_spin_lock_facade_test.cc",
264        "interrupt_spin_lock_facade_test_c.c",
265    ],
266    deps = [
267        ":interrupt_spin_lock",
268        "//pw_preprocessor",
269        "//pw_unit_test",
270    ],
271)
272