SpinLock: Add releasePrematurely for early releases

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