File tree Expand file tree Collapse file tree 1 file changed +5
-11
lines changed
Expand file tree Collapse file tree 1 file changed +5
-11
lines changed Original file line number Diff line number Diff line change 3131
3232#include < atomic>
3333#include < cstdint>
34+ #include < mutex>
3435#include < type_traits>
3536
3637#include " absl/base/attributes.h"
@@ -247,25 +248,18 @@ class ABSL_LOCKABLE ABSL_ATTRIBUTE_WARN_UNUSED SpinLock {
247248
248249// Corresponding locker object that arranges to acquire a spinlock for
249250// the duration of a C++ scope.
250- class ABSL_SCOPED_LOCKABLE [[nodiscard]] SpinLockHolder {
251+ class ABSL_SCOPED_LOCKABLE [[nodiscard]] SpinLockHolder
252+ : public std::lock_guard<SpinLock> {
251253 public:
252254 inline explicit SpinLockHolder (
253255 SpinLock& l ABSL_INTERNAL_ATTRIBUTE_CAPTURED_BY (this ))
254256 ABSL_EXCLUSIVE_LOCK_FUNCTION (l)
255- : lock_ (l) {
256- l.lock ();
257- }
257+ : std::lock_guard<SpinLock>(l) {}
258258 ABSL_DEPRECATE_AND_INLINE ()
259259 inline explicit SpinLockHolder (SpinLock* l) ABSL_EXCLUSIVE_LOCK_FUNCTION (l)
260260 : SpinLockHolder (*l) {}
261261
262- inline ~SpinLockHolder () ABSL_UNLOCK_FUNCTION () { lock_.unlock (); }
263-
264- SpinLockHolder (const SpinLockHolder&) = delete ;
265- SpinLockHolder& operator =(const SpinLockHolder&) = delete ;
266-
267- private:
268- SpinLock& lock_;
262+ inline ~SpinLockHolder () ABSL_UNLOCK_FUNCTION () = default ;
269263};
270264
271265// Register a hook for profiling support.
You can’t perform that action at this time.
0 commit comments