SpinLock: Add releasePrematurely for early releases

This commit is contained in:
2025-11-14 01:38:06 -04:00
parent 39691175e7
commit 324e3d1f6a
+13 -1
View File
@@ -80,15 +80,26 @@ public:
{ {
public: public:
explicit Guard(SpinLock& lock) explicit Guard(SpinLock& lock)
: lock_(lock) : lock_(lock), unlocked_(false)
{ {
lock_.acquire(); lock_.acquire();
} }
~Guard() ~Guard()
{ {
if (!unlocked_) {
lock_.release(); lock_.release();
} }
}
void unlockPrematurely()
{
if (!unlocked_)
{
lock_.release();
unlocked_ = true;
}
}
// Non-copyable, non-movable // Non-copyable, non-movable
Guard(const Guard&) = delete; Guard(const Guard&) = delete;
@@ -98,6 +109,7 @@ public:
private: private:
SpinLock& lock_; SpinLock& lock_;
bool unlocked_;
}; };
private: private: