X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FAtomicHashMap-inl.h;h=4752cdd3aec69c345e36f12b8553e422ba421a30;hb=d7c649a4db69003794c11771ae40738e92a36acd;hp=a2f497afdf00ef9731e2ccbfee340d358f4e6efc;hpb=2129f9b5e34ae3a958e50f9fcb3032086366abb8;p=folly.git diff --git a/folly/AtomicHashMap-inl.h b/folly/AtomicHashMap-inl.h index a2f497af..4752cdd3 100644 --- a/folly/AtomicHashMap-inl.h +++ b/folly/AtomicHashMap-inl.h @@ -1,5 +1,5 @@ /* - * Copyright 2013 Facebook, Inc. + * Copyright 2015 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ #error "This should only be included by AtomicHashMap.h" #endif -#include "folly/detail/AtomicHashUtils.h" +#include namespace folly { @@ -32,14 +32,14 @@ AtomicHashMap::defaultConfig; template AtomicHashMap:: -AtomicHashMap(size_t size, const Config& config) +AtomicHashMap(size_t finalSizeEst, const Config& config) : kGrowthFrac_(config.growthFactor < 0 ? 1.0 - config.maxLoadFactor : config.growthFactor) { CHECK(config.maxLoadFactor > 0.0 && config.maxLoadFactor < 1.0); - subMaps_[0].store(SubMap::create(size, config).release(), + subMaps_[0].store(SubMap::create(finalSizeEst, config).release(), std::memory_order_relaxed); - auto numSubMaps = kNumSubMaps_; - FOR_EACH_RANGE(i, 1, numSubMaps) { + auto subMapCount = kNumSubMaps_; + FOR_EACH_RANGE(i, 1, subMapCount) { subMaps_[i].store(nullptr, std::memory_order_relaxed); } numMapsAllocated_.store(1, std::memory_order_relaxed); @@ -78,7 +78,7 @@ typename AtomicHashMap::SimpleRetT AtomicHashMap:: insertInternal(key_type key, T&& value) { beginInsertInternal: - int nextMapIdx = // this maintains our state + auto nextMapIdx = // this maintains our state numMapsAllocated_.load(std::memory_order_acquire); typename SubMap::SimpleRetT ret; FOR_EACH_RANGE(i, 0, nextMapIdx) { @@ -155,7 +155,7 @@ typename AtomicHashMap::iterator AtomicHashMap:: find(KeyT k) { SimpleRetT ret = findInternal(k); - if (ret.i >= numMapsAllocated_.load(std::memory_order_acquire)) { + if (!ret.success) { return end(); } SubMap* subMap = subMaps_[ret.i].load(std::memory_order_relaxed); @@ -370,9 +370,7 @@ struct AtomicHashMap::ahm_iterator : ahm_(ahm) , subMap_(subMap) , subIt_(subIt) - { - checkAdvanceToNextSubmap(); - } + {} friend class boost::iterator_core_access; @@ -408,7 +406,7 @@ struct AtomicHashMap::ahm_iterator SubMap* thisMap = ahm_->subMaps_[subMap_]. load(std::memory_order_relaxed); - if (subIt_ == thisMap->end()) { + while (subIt_ == thisMap->end()) { // This sub iterator is done, advance to next one if (subMap_ + 1 < ahm_->numMapsAllocated_.load(std::memory_order_acquire)) { @@ -417,6 +415,7 @@ struct AtomicHashMap::ahm_iterator subIt_ = thisMap->begin(); } else { ahm_ = nullptr; + return; } } }