Skip to content

Commit 2fa6434

Browse files
Add scope guard
Summary: Small change: replace mutex_.Lock/mutex_.Unlock() with scope guard Test Plan: make all check Reviewers: igor, sdong Reviewed By: sdong Subscribers: leveldb Differential Revision: https://reviews.facebook.net/D21609
1 parent 06a52bd commit 2fa6434

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

db/db_impl.cc

+16-14
Original file line numberDiff line numberDiff line change
@@ -1865,21 +1865,23 @@ Status DBImpl::FlushMemTable(ColumnFamilyData* cfd,
18651865
w.done = false;
18661866
w.timeout_hint_us = kNoTimeOut;
18671867

1868-
WriteContext context;
1869-
mutex_.Lock();
1870-
Status s = BeginWrite(&w, 0);
1871-
assert(s.ok() && !w.done); // No timeout and nobody should do our job
1872-
1873-
// SetNewMemtableAndNewLogFile() will release and reacquire mutex
1874-
// during execution
1875-
s = SetNewMemtableAndNewLogFile(cfd, &context);
1876-
cfd->imm()->FlushRequested();
1877-
MaybeScheduleFlushOrCompaction();
1868+
Status s;
1869+
{
1870+
WriteContext context;
1871+
MutexLock guard_lock(&mutex_);
1872+
s = BeginWrite(&w, 0);
1873+
assert(s.ok() && !w.done); // No timeout and nobody should do our job
1874+
1875+
// SetNewMemtableAndNewLogFile() will release and reacquire mutex
1876+
// during execution
1877+
s = SetNewMemtableAndNewLogFile(cfd, &context);
1878+
cfd->imm()->FlushRequested();
1879+
MaybeScheduleFlushOrCompaction();
18781880

1879-
assert(!writers_.empty());
1880-
assert(writers_.front() == &w);
1881-
EndWrite(&w, &w, s);
1882-
mutex_.Unlock();
1881+
assert(!writers_.empty());
1882+
assert(writers_.front() == &w);
1883+
EndWrite(&w, &w, s);
1884+
}
18831885

18841886

18851887
if (s.ok() && options.wait) {

0 commit comments

Comments
 (0)