Skip to content

Commit

Permalink
Lock the mutex when declare the lock (#971)
Browse files Browse the repository at this point in the history
Signed-off-by: Tao He <[email protected]>
  • Loading branch information
sighingnow authored Sep 9, 2022
1 parent 745faa1 commit b478b90
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/server/memory/usage.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class ColdObjectTracker
~LRU() = default;

void Ref(ID id, std::shared_ptr<P> payload) {
std::unique_lock<decltype(mu_)> locked;
std::unique_lock<decltype(mu_)> locked(mu_);
auto it = map_.find(id);
if (it == map_.end()) {
list_.emplace_front(id, payload);
Expand All @@ -221,7 +221,7 @@ class ColdObjectTracker
}

bool CheckExist(ID id) const {
std::shared_lock<decltype(mu_)> shared_locked;
std::shared_lock<decltype(mu_)> shared_locked(mu_);
return map_.find(id) != map_.end();
}

Expand All @@ -236,7 +236,7 @@ class ColdObjectTracker
*/
Status Unref(const ID& id, bool fast_delete,
std::shared_ptr<Der> store_ptr) {
std::unique_lock<decltype(mu_)> locked;
std::unique_lock<decltype(mu_)> locked(mu_);
auto it = map_.find(id);
if (it == map_.end()) {
auto it = spilled_obj_.find(id);
Expand All @@ -258,7 +258,7 @@ class ColdObjectTracker
}

Status Spill(size_t sz, std::shared_ptr<Der> bulk_store_ptr) {
std::unique_lock<decltype(mu_)> locked;
std::unique_lock<decltype(mu_)> locked(mu_);
size_t spilled_sz = 0;
auto st = Status::OK();
auto it = list_.rbegin();
Expand Down Expand Up @@ -287,7 +287,7 @@ class ColdObjectTracker
}

bool CheckSpilled(const ID& id) {
std::shared_lock<decltype(mu_)> lock;
std::shared_lock<decltype(mu_)> lock(mu_);
return spilled_obj_.find(id) != spilled_obj_.end();
}

Expand Down

0 comments on commit b478b90

Please sign in to comment.