SpinLock: Add releasePrematurely for early releases
This commit is contained in:
+13
-1
@@ -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:
|
||||||
|
|||||||
Reference in New Issue
Block a user