• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #pragma once
15 
16 // PW_MULTISINK_LOCK_INTERRUPT_SAFE controls whether an interrupt-safe lock is
17 // used when reading and writing from the underlying ring-buffer. This is
18 // enabled by default, using an interrupt spin-lock instead of a mutex.
19 // Disabling this alters the entry precondition of the multisink, requiring that
20 // it not be invoked from an interrupt context.
21 #if !defined(PW_MULTISINK_CONFIG_LOCK_INTERRUPT_SAFE)
22 #define PW_MULTISINK_CONFIG_LOCK_INTERRUPT_SAFE 1
23 #endif  // !defined(PW_MULTISINK_CONFIG_LOCK_INTERRUPT_SAFE)
24 
25 #if PW_MULTISINK_CONFIG_LOCK_INTERRUPT_SAFE
26 #include "pw_sync/interrupt_spin_lock.h"
27 #else  // !PW_MULTISINK_CONFIG_LOCK_INTERRUPT_SAFE
28 #include "pw_sync/mutex.h"
29 #endif  // PW_MULTISINK_CONFIG_LOCK_INTERRUPT_SAFE
30 
31 namespace pw {
32 namespace multisink {
33 
34 #if PW_MULTISINK_CONFIG_LOCK_INTERRUPT_SAFE
35 using LockType = pw::sync::InterruptSpinLock;
36 #else   // !PW_MULTISINK_CONFIG_LOCK_INTERRUPT_SAFE
37 using LockType = pw::sync::Mutex;
38 #endif  // PW_MULTISINK_CONFIG_LOCK_INTERRUPT_SAFE
39 
40 }  // namespace multisink
41 }  // namespace pw
42