File tree Expand file tree Collapse file tree 1 file changed +11
-11
lines changed Expand file tree Collapse file tree 1 file changed +11
-11
lines changed Original file line number Diff line number Diff line change @@ -29,26 +29,26 @@ namespace platform {
29
29
*/
30
30
template <typename LockType>
31
31
class LockGuardPtr {
32
- using LockGuardType = std::lock_guard<LockType>;
33
-
34
32
public:
35
- class LockGuardDeleter {
36
- public:
37
- void operator ()(LockGuardType* guard) { guard->~LockGuardType (); }
38
- };
39
-
40
33
explicit LockGuardPtr (std::unique_ptr<LockType>& lock_ptr) // NOLINT
41
- : guard_ptr_(lock_ptr ? new (guard_buffer_) LockGuardType(*lock_ptr)
42
- : nullptr) {}
34
+ : lock_(lock_ptr.get()) {
35
+ if (lock_) {
36
+ lock_->lock ();
37
+ }
38
+ }
39
+ ~LockGuardPtr () {
40
+ if (lock_) {
41
+ lock_->unlock ();
42
+ }
43
+ }
43
44
44
45
LockGuardPtr (const LockGuardPtr&) = delete ;
45
46
LockGuardPtr& operator =(const LockGuardPtr&) = delete ;
46
47
LockGuardPtr (LockGuardPtr&&) = delete ;
47
48
LockGuardPtr& operator =(LockGuardPtr&&) = delete ;
48
49
49
50
private:
50
- uint8_t guard_buffer_[sizeof (LockGuardType)];
51
- std::unique_ptr<LockGuardType, LockGuardDeleter> guard_ptr_;
51
+ LockType* lock_;
52
52
};
53
53
54
54
} // namespace platform
You can’t perform that action at this time.
0 commit comments