C/C++ API Reference
Loading...
Searching...
No Matches
no_lock.h
1// Copyright 2025 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 <type_traits>
17
18#include "pw_sync/lock_annotations.h"
19
20namespace pw::sync {
21
23
27class PW_LOCKABLE("pw::sync::NoLock") NoLock {
28 public:
29 constexpr void lock() PW_EXCLUSIVE_LOCK_FUNCTION() {}
30 constexpr void unlock() PW_UNLOCK_FUNCTION() {}
31 [[nodiscard]] bool try_lock() PW_EXCLUSIVE_TRYLOCK_FUNCTION(true) {
32 return true;
33 }
34};
35
42template <bool kEnableLocking, typename LockType>
43using MaybeLock = std::conditional_t<kEnableLocking, LockType, NoLock>;
44
46
47} // namespace pw::sync
Definition: no_lock.h:27
#define PW_LOCKABLE(name)
Definition: lock_annotations.h:208
#define PW_EXCLUSIVE_TRYLOCK_FUNCTION(...)
Definition: lock_annotations.h:260
#define PW_EXCLUSIVE_LOCK_FUNCTION(...)
Definition: lock_annotations.h:230
std::conditional_t< kEnableLocking, LockType, NoLock > MaybeLock
Definition: no_lock.h:43
#define PW_UNLOCK_FUNCTION(...)
Definition: lock_annotations.h:247
Definition: binary_semaphore.h:26