CxCli: better TryRemove.
GitOrigin-RevId: ef4394f1dd2d1fdf6609412ec666954316aafa66
This commit is contained in:
parent
e3efbd9c84
commit
c8a784f0ca
|
@ -49,9 +49,15 @@ public:
|
||||||
value = it->second;
|
value = it->second;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
void TryRemove(Key key, Value &value) {
|
bool TryRemove(Key key, Value &value) {
|
||||||
std::lock_guard<std::mutex> guard(mutex_);
|
std::lock_guard<std::mutex> guard(mutex_);
|
||||||
impl_.erase(key);
|
auto it = impl_.find(key);
|
||||||
|
if (it == impl_.end()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
value = std::move(it->second);
|
||||||
|
impl_.erase(it);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
Value &operator [] (Key key) {
|
Value &operator [] (Key key) {
|
||||||
std::lock_guard<std::mutex> guard(mutex_);
|
std::lock_guard<std::mutex> guard(mutex_);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user