Skip to content

Commit

Permalink
Add scope guard
Browse files Browse the repository at this point in the history
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
  • Loading branch information
StanislavGlebik committed Aug 12, 2014
1 parent 06a52bd commit 2fa6434
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions db/db_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1865,21 +1865,23 @@ Status DBImpl::FlushMemTable(ColumnFamilyData* cfd,
w.done = false;
w.timeout_hint_us = kNoTimeOut;

WriteContext context;
mutex_.Lock();
Status s = BeginWrite(&w, 0);
assert(s.ok() && !w.done); // No timeout and nobody should do our job

// SetNewMemtableAndNewLogFile() will release and reacquire mutex
// during execution
s = SetNewMemtableAndNewLogFile(cfd, &context);
cfd->imm()->FlushRequested();
MaybeScheduleFlushOrCompaction();
Status s;
{
WriteContext context;
MutexLock guard_lock(&mutex_);
s = BeginWrite(&w, 0);
assert(s.ok() && !w.done); // No timeout and nobody should do our job

// SetNewMemtableAndNewLogFile() will release and reacquire mutex
// during execution
s = SetNewMemtableAndNewLogFile(cfd, &context);
cfd->imm()->FlushRequested();
MaybeScheduleFlushOrCompaction();

assert(!writers_.empty());
assert(writers_.front() == &w);
EndWrite(&w, &w, s);
mutex_.Unlock();
assert(!writers_.empty());
assert(writers_.front() == &w);
EndWrite(&w, &w, s);
}


if (s.ok() && options.wait) {
Expand Down

0 comments on commit 2fa6434

Please sign in to comment.