Skip to content

Commit 1673124

Browse files
committed
use unique ptr to hold auto_grown_mutex_ for default copy and move constructor
1 parent add9ed3 commit 1673124

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

paddle/fluid/framework/selected_rows.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ bool SelectedRows::Set(int64_t key, const framework::Tensor& value) {
153153
}
154154
PADDLE_ENFORCE_EQ(value.dims()[0], static_cast<size_t>(1),
155155
"The first dim of value should be 1.");
156-
std::lock_guard<std::mutex> lock(auto_grown_mutex_);
156+
std::lock_guard<std::mutex> lock(*auto_grown_mutex_.get());
157157
auto index = Index(key);
158158
bool is_new_key = false;
159159
if (index == -1) {

paddle/fluid/framework/selected_rows.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ limitations under the License. */
1515
#pragma once
1616

1717
#include <algorithm>
18+
#include <memory>
1819
#include <utility>
1920
#include <vector>
2021

@@ -46,11 +47,13 @@ class SelectedRows {
4647
SelectedRows(const std::vector<int64_t>& rows, const int64_t& height)
4748
: rows_(rows), height_(height) {
4849
value_.reset(new Tensor());
50+
auto_grown_mutex_.reset(new std::mutex);
4951
}
5052

5153
SelectedRows() {
5254
height_ = 0;
5355
value_.reset(new Tensor());
56+
auto_grown_mutex_.reset(new std::mutex);
5457
}
5558

5659
platform::Place place() const { return value_->place(); }
@@ -125,7 +128,7 @@ class SelectedRows {
125128
Vector<int64_t> rows_;
126129
std::unique_ptr<Tensor> value_{nullptr};
127130
int64_t height_;
128-
std::mutex auto_grown_mutex_;
131+
std::unique_ptr<std::mutex> auto_grown_mutex_{nullptr};
129132
};
130133

131134
/*

0 commit comments

Comments
 (0)