Pigweed
 
Loading...
Searching...
No Matches
interrupt_spin_lock.h
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#pragma once
15
16#include <stdbool.h>
17
18#include "pw_preprocessor/util.h"
19#include "pw_sync/lock_annotations.h"
20
21#ifdef __cplusplus
22
23#include "pw_sync/virtual_basic_lockable.h"
24#include "pw_sync_backend/interrupt_spin_lock_native.h"
25
26namespace pw::sync {
27
48class PW_LOCKABLE("pw::sync::InterruptSpinLock") InterruptSpinLock {
49 public:
50 using native_handle_type = backend::NativeInterruptSpinLockHandle;
51
52 constexpr InterruptSpinLock();
53 ~InterruptSpinLock() = default;
54 InterruptSpinLock(const InterruptSpinLock&) = delete;
56 InterruptSpinLock& operator=(const InterruptSpinLock&) = delete;
57 InterruptSpinLock& operator=(InterruptSpinLock&&) = delete;
58
62 void lock() PW_EXCLUSIVE_LOCK_FUNCTION();
63
68 [[nodiscard]] bool try_lock() PW_EXCLUSIVE_TRYLOCK_FUNCTION(true);
69
74 void unlock() PW_UNLOCK_FUNCTION();
75
76 [[nodiscard]] native_handle_type native_handle();
77
78 private:
80 backend::NativeInterruptSpinLock native_type_;
81};
82
83class PW_LOCKABLE("pw::sync::VirtualInterruptSpinLock")
85};
86
87} // namespace pw::sync
88
89#include "pw_sync_backend/interrupt_spin_lock_inline.h"
90
92
93#else // !defined(__cplusplus)
94
96
97#endif // __cplusplus
98
99PW_EXTERN_C_START
100
103void pw_sync_InterruptSpinLock_Lock(pw_sync_InterruptSpinLock* spin_lock)
104 PW_NO_LOCK_SAFETY_ANALYSIS;
105
108bool pw_sync_InterruptSpinLock_TryLock(pw_sync_InterruptSpinLock* spin_lock)
109 PW_NO_LOCK_SAFETY_ANALYSIS;
110
113void pw_sync_InterruptSpinLock_Unlock(pw_sync_InterruptSpinLock* spin_lock)
114 PW_NO_LOCK_SAFETY_ANALYSIS;
115
116PW_EXTERN_C_END
Definition: virtual_basic_lockable.h:108
Definition: interrupt_spin_lock.h:48
Definition: interrupt_spin_lock.h:84
Provides basic helpers for reading and writing UTF-8 encoded strings.
Definition: alignment.h:27