Internal Interface Wrap
API reference
Loading...
Searching...
No Matches
SoftChipSelectGuard.h
Go to the documentation of this file.
1
14#pragma once
15
16#include <utility>
17
31template <typename AssertFn, typename DeassertFn>
33public:
34 SoftChipSelectGuard(AssertFn assert_fn, DeassertFn deassert_fn) noexcept
35 : deassert_(std::move(deassert_fn)), armed_(true) {
36 assert_fn();
37 }
38
40 Release();
41 }
42
45
47 : deassert_(std::move(other.deassert_)), armed_(other.armed_) {
48 other.armed_ = false;
49 }
50
52 if (this != &other) {
53 Release();
54 deassert_ = std::move(other.deassert_);
55 armed_ = other.armed_;
56 other.armed_ = false;
57 }
58 return *this;
59 }
60
62 void Release() noexcept {
63 if (armed_) {
64 deassert_();
65 armed_ = false;
66 }
67 }
68
69 [[nodiscard]] bool OwnsCs() const noexcept { return armed_; }
70
71private:
72 DeassertFn deassert_;
73 bool armed_;
74};
75
77template <typename AssertFn, typename DeassertFn>
79 AssertFn assert_fn, DeassertFn deassert_fn) noexcept {
82}
SoftChipSelectGuard< AssertFn, DeassertFn > MakeSoftChipSelectGuard(AssertFn assert_fn, DeassertFn deassert_fn) noexcept
Deduce guard type from assert/deassert callables.
Definition SoftChipSelectGuard.h:78
RAII soft-CS: runs assert_fn on construction and deassert_fn on destruction (including early return /...
Definition SoftChipSelectGuard.h:32
void Release() noexcept
Early deassert (idempotent). Destructor becomes a no-op.
Definition SoftChipSelectGuard.h:62
bool armed_
Definition SoftChipSelectGuard.h:73
SoftChipSelectGuard(SoftChipSelectGuard &&other) noexcept
Definition SoftChipSelectGuard.h:46
bool OwnsCs() const noexcept
Definition SoftChipSelectGuard.h:69
DeassertFn deassert_
Definition SoftChipSelectGuard.h:72
SoftChipSelectGuard & operator=(const SoftChipSelectGuard &)=delete
SoftChipSelectGuard(AssertFn assert_fn, DeassertFn deassert_fn) noexcept
Definition SoftChipSelectGuard.h:34
~SoftChipSelectGuard() noexcept
Definition SoftChipSelectGuard.h:39
SoftChipSelectGuard(const SoftChipSelectGuard &)=delete
SoftChipSelectGuard & operator=(SoftChipSelectGuard &&other) noexcept
Definition SoftChipSelectGuard.h:51