Skip to content

Commit 6ae0b91

Browse files
committed
Clean LockGuardPtr
test=develop
1 parent 1420c3b commit 6ae0b91

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

paddle/fluid/platform/lock_guard_ptr.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,26 @@ namespace platform {
2929
*/
3030
template <typename LockType>
3131
class LockGuardPtr {
32-
using LockGuardType = std::lock_guard<LockType>;
33-
3432
public:
35-
class LockGuardDeleter {
36-
public:
37-
void operator()(LockGuardType* guard) { guard->~LockGuardType(); }
38-
};
39-
4033
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+
}
4344

4445
LockGuardPtr(const LockGuardPtr&) = delete;
4546
LockGuardPtr& operator=(const LockGuardPtr&) = delete;
4647
LockGuardPtr(LockGuardPtr&&) = delete;
4748
LockGuardPtr& operator=(LockGuardPtr&&) = delete;
4849

4950
private:
50-
uint8_t guard_buffer_[sizeof(LockGuardType)];
51-
std::unique_ptr<LockGuardType, LockGuardDeleter> guard_ptr_;
51+
LockType* lock_;
5252
};
5353

5454
} // namespace platform

0 commit comments

Comments
 (0)