C/C++ API Reference
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
29
50class PW_LOCKABLE("pw::sync::InterruptSpinLock") InterruptSpinLock {
51 public:
52 using native_handle_type = backend::NativeInterruptSpinLockHandle;
53
54 constexpr InterruptSpinLock();
55 ~InterruptSpinLock() = default;
56 InterruptSpinLock(const InterruptSpinLock&) = delete;
58 InterruptSpinLock& operator=(const InterruptSpinLock&) = delete;
59 InterruptSpinLock& operator=(InterruptSpinLock&&) = delete;
60
65
70 [[nodiscard]] bool try_lock() PW_EXCLUSIVE_TRYLOCK_FUNCTION(true);
71
75 void unlock() PW_UNLOCK_FUNCTION();
76
77 [[nodiscard]] native_handle_type native_handle();
78
79 private:
81 backend::NativeInterruptSpinLock native_type_;
82};
83
86};
87
89
90} // namespace pw::sync
91
92#include "pw_sync_backend/interrupt_spin_lock_inline.h"
93
95
96#else // !defined(__cplusplus)
97
99
100#endif // __cplusplus
101
102PW_EXTERN_C_START
103
105
110
115
120
122
123PW_EXTERN_C_END
Definition: virtual_basic_lockable.h:109
Definition: interrupt_spin_lock.h:50
Definition: interrupt_spin_lock.h:85
#define PW_LOCKABLE(name)
Definition: lock_annotations.h:208
void pw_sync_InterruptSpinLock_Unlock(pw_sync_InterruptSpinLock *spin_lock)
#define PW_EXCLUSIVE_TRYLOCK_FUNCTION(...)
Definition: lock_annotations.h:260
void pw_sync_InterruptSpinLock_Lock(pw_sync_InterruptSpinLock *spin_lock)
#define PW_NO_LOCK_SAFETY_ANALYSIS
Definition: lock_annotations.h:292
bool pw_sync_InterruptSpinLock_TryLock(pw_sync_InterruptSpinLock *spin_lock)
#define PW_EXCLUSIVE_LOCK_FUNCTION(...)
Definition: lock_annotations.h:230
#define PW_UNLOCK_FUNCTION(...)
Definition: lock_annotations.h:247
Definition: binary_semaphore.h:26
The Pigweed namespace.
Definition: alignment.h:27