Skip to content

Commit

Permalink
use unique ptr to hold auto_grown_mutex_ for default copy and move co…
Browse files Browse the repository at this point in the history
…nstructor
  • Loading branch information
jacquesqiao committed May 29, 2018
1 parent add9ed3 commit 1673124
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion paddle/fluid/framework/selected_rows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ bool SelectedRows::Set(int64_t key, const framework::Tensor& value) {
}
PADDLE_ENFORCE_EQ(value.dims()[0], static_cast<size_t>(1),
"The first dim of value should be 1.");
std::lock_guard<std::mutex> lock(auto_grown_mutex_);
std::lock_guard<std::mutex> lock(*auto_grown_mutex_.get());
auto index = Index(key);
bool is_new_key = false;
if (index == -1) {
Expand Down
5 changes: 4 additions & 1 deletion paddle/fluid/framework/selected_rows.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ limitations under the License. */
#pragma once

#include <algorithm>
#include <memory>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -46,11 +47,13 @@ class SelectedRows {
SelectedRows(const std::vector<int64_t>& rows, const int64_t& height)
: rows_(rows), height_(height) {
value_.reset(new Tensor());
auto_grown_mutex_.reset(new std::mutex);
}

SelectedRows() {
height_ = 0;
value_.reset(new Tensor());
auto_grown_mutex_.reset(new std::mutex);
}

platform::Place place() const { return value_->place(); }
Expand Down Expand Up @@ -125,7 +128,7 @@ class SelectedRows {
Vector<int64_t> rows_;
std::unique_ptr<Tensor> value_{nullptr};
int64_t height_;
std::mutex auto_grown_mutex_;
std::unique_ptr<std::mutex> auto_grown_mutex_{nullptr};
};

/*
Expand Down

0 comments on commit 1673124

Please sign in to comment.