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 // Enum for different lock configurations. 17 // Use non-obvious numbers so users use the macro instead of an integer 18 #define PW_MULTISINK_INTERRUPT_SPIN_LOCK 100 19 #define PW_MULTISINK_MUTEX 200 20 #define PW_MULTISINK_VIRTUAL_LOCK 300 21 22 // PW_MULTISINK_CONFIG_LOCK_TYPE controls which lock is used when reading and 23 // writing from the underlying ring-buffer. The interrupt spin lock is 24 // enabled by default if PW_MULTISINK_CONFIG_LOCK_TYPE is not set. Otherwise, 25 // one of the following locking implementations can be set using the enums 26 // above. PW_MULTISINK_VIRTUAL_LOCK can be used if the user wants to provide 27 // their own locking implementation. 28 #ifndef PW_MULTISINK_CONFIG_LOCK_TYPE 29 // Backwards compatibility 30 #ifdef PW_MULTISINK_LOCK_INTERRUPT_SAFE 31 #warning "Multisink PW_MULTISINK_INTERRUPT_SPIN_LOCK is deprecated!!!" 32 #if PW_MULTISINK_LOCK_INTERRUPT_SAFE 33 #define PW_MULTISINK_CONFIG_LOCK_TYPE PW_MULTISINK_INTERRUPT_SPIN_LOCK 34 #else 35 #define PW_MULTISINK_CONFIG_LOCK_TYPE PW_MULTISINK_MUTEX 36 #endif 37 #else 38 // Default to use interrupt spin lock. 39 #define PW_MULTISINK_CONFIG_LOCK_TYPE PW_MULTISINK_INTERRUPT_SPIN_LOCK 40 #endif 41 #endif // PW_MULTISINK_CONFIG_LOCK_TYPE 42 43 static_assert(PW_MULTISINK_CONFIG_LOCK_TYPE == 44 PW_MULTISINK_INTERRUPT_SPIN_LOCK || 45 PW_MULTISINK_CONFIG_LOCK_TYPE == PW_MULTISINK_MUTEX || 46 PW_MULTISINK_CONFIG_LOCK_TYPE == PW_MULTISINK_VIRTUAL_LOCK); 47 48 #if PW_MULTISINK_CONFIG_LOCK_TYPE == PW_MULTISINK_INTERRUPT_SPIN_LOCK 49 #include "pw_sync/interrupt_spin_lock.h" 50 #elif PW_MULTISINK_CONFIG_LOCK_TYPE == PW_MULTISINK_VIRTUAL_LOCK 51 #include "pw_sync/virtual_basic_lockable.h" 52 #elif PW_MULTISINK_CONFIG_LOCK_TYPE == PW_MULTISINK_MUTEX 53 #include "pw_sync/mutex.h" 54 #endif // PW_MULTISINK_CONFIG_LOCK_INTERRUPT_SAFE 55 56 namespace pw { 57 namespace multisink { 58 59 #if PW_MULTISINK_CONFIG_LOCK_TYPE == PW_MULTISINK_INTERRUPT_SPIN_LOCK 60 using LockType = pw::sync::InterruptSpinLock; 61 #elif PW_MULTISINK_CONFIG_LOCK_TYPE == PW_MULTISINK_VIRTUAL_LOCK 62 using LockType = pw::sync::VirtualBasicLockable&; 63 #elif PW_MULTISINK_CONFIG_LOCK_TYPE == PW_MULTISINK_MUTEX 64 using LockType = pw::sync::Mutex; 65 #endif // PW_MULTISINK_CONFIG_LOCK_INTERRUPT_SAFE 66 67 } // namespace multisink 68 } // namespace pw 69