diff --git a/include/spinLock.h b/include/spinLock.h index 0d22055..0d6b8e5 100644 --- a/include/spinLock.h +++ b/include/spinLock.h @@ -80,14 +80,25 @@ public: { public: explicit Guard(SpinLock& lock) - : lock_(lock) + : lock_(lock), unlocked_(false) { lock_.acquire(); } ~Guard() { - lock_.release(); + if (!unlocked_) { + lock_.release(); + } + } + + void unlockPrematurely() + { + if (!unlocked_) + { + lock_.release(); + unlocked_ = true; + } } // Non-copyable, non-movable @@ -98,6 +109,7 @@ public: private: SpinLock& lock_; + bool unlocked_; }; private: