summaryrefslogtreecommitdiff
path: root/db/db_impl.cc
diff options
context:
space:
mode:
authorcostan <costan@google.com>2018-03-23 12:50:14 -0700
committerVictor Costan <pwnall@chromium.org>2018-03-23 12:56:14 -0700
commit0db30413a4cfa8c980e675ba5cb96717d688af92 (patch)
tree6194fe595f5bac1f71216bf659cb95f4e78cd773 /db/db_impl.cc
parent04f39105c5a418905da8b7657ca244d672c99d3b (diff)
downloadleveldb-0db30413a4cfa8c980e675ba5cb96717d688af92.tar.gz
leveldb: Add more thread safety annotations.
After this CL, all classes with Mutex members should be covered by annotations. Exceptions are atomic members, which shouldn't need locking, and DBImpl members that cause errors when annotated, which will be tackled separately. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=190260865
Diffstat (limited to 'db/db_impl.cc')
-rw-r--r--db/db_impl.cc21
1 files changed, 11 insertions, 10 deletions
diff --git a/db/db_impl.cc b/db/db_impl.cc
index 8484e46..cd8792e 100644
--- a/db/db_impl.cc
+++ b/db/db_impl.cc
@@ -1053,11 +1053,15 @@ Status DBImpl::DoCompactionWork(CompactionState* compact) {
}
namespace {
+
struct IterState {
- port::Mutex* mu;
- Version* version;
- MemTable* mem;
- MemTable* imm;
+ port::Mutex* const mu;
+ Version* const version GUARDED_BY(mu);
+ MemTable* const mem GUARDED_BY(mu);
+ MemTable* const imm GUARDED_BY(mu);
+
+ IterState(port::Mutex* mutex, MemTable* mem, MemTable* imm, Version* version)
+ : mu(mutex), version(version), mem(mem), imm(imm) { }
};
static void CleanupIteratorState(void* arg1, void* arg2) {
@@ -1069,12 +1073,12 @@ static void CleanupIteratorState(void* arg1, void* arg2) {
state->mu->Unlock();
delete state;
}
-} // namespace
+
+} // anonymous namespace
Iterator* DBImpl::NewInternalIterator(const ReadOptions& options,
SequenceNumber* latest_snapshot,
uint32_t* seed) {
- IterState* cleanup = new IterState;
mutex_.Lock();
*latest_snapshot = versions_->LastSequence();
@@ -1091,10 +1095,7 @@ Iterator* DBImpl::NewInternalIterator(const ReadOptions& options,
NewMergingIterator(&internal_comparator_, &list[0], list.size());
versions_->current()->Ref();
- cleanup->mu = &mutex_;
- cleanup->mem = mem_;
- cleanup->imm = imm_;
- cleanup->version = versions_->current();
+ IterState* cleanup = new IterState(&mutex_, mem_, imm_, versions_->current());
internal_iter->RegisterCleanup(CleanupIteratorState, cleanup, NULL);
*seed = ++seed_;