From 6ae0b91b39038dabe13107b9d55b7f306ca92e59 Mon Sep 17 00:00:00 2001 From: Yu Yang Date: Fri, 9 Nov 2018 14:07:40 +0800 Subject: [PATCH] Clean LockGuardPtr test=develop --- paddle/fluid/platform/lock_guard_ptr.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/paddle/fluid/platform/lock_guard_ptr.h b/paddle/fluid/platform/lock_guard_ptr.h index 220c538bc..bff24e74a 100644 --- a/paddle/fluid/platform/lock_guard_ptr.h +++ b/paddle/fluid/platform/lock_guard_ptr.h @@ -29,17 +29,18 @@ namespace platform { */ template class LockGuardPtr { - using LockGuardType = std::lock_guard; - public: - class LockGuardDeleter { - public: - void operator()(LockGuardType* guard) { guard->~LockGuardType(); } - }; - explicit LockGuardPtr(std::unique_ptr& lock_ptr) // NOLINT - : guard_ptr_(lock_ptr ? new (guard_buffer_) LockGuardType(*lock_ptr) - : nullptr) {} + : lock_(lock_ptr.get()) { + if (lock_) { + lock_->lock(); + } + } + ~LockGuardPtr() { + if (lock_) { + lock_->unlock(); + } + } LockGuardPtr(const LockGuardPtr&) = delete; LockGuardPtr& operator=(const LockGuardPtr&) = delete; @@ -47,8 +48,7 @@ class LockGuardPtr { LockGuardPtr& operator=(LockGuardPtr&&) = delete; private: - uint8_t guard_buffer_[sizeof(LockGuardType)]; - std::unique_ptr guard_ptr_; + LockType* lock_; }; } // namespace platform -- GitLab