/*
- * Copyright 2015 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#ifndef FOLLY_ATOMICUNORDEREDMAP_H
-#define FOLLY_ATOMICUNORDEREDMAP_H
+
+#pragma once
#include <atomic>
#include <functional>
#include <system_error>
#include <type_traits>
#include <stdint.h>
-#include <unistd.h>
-#include <sys/mman.h>
-#include <folly/Likely.h>
+
#include <folly/Bits.h>
#include <folly/Conv.h>
+#include <folly/Likely.h>
#include <folly/Random.h>
#include <folly/detail/AtomicUnorderedMapUtils.h>
+#include <folly/portability/SysMman.h>
+#include <folly/portability/Unistd.h>
+
#include <boost/type_traits/has_trivial_destructor.hpp>
#include <limits>
(boost::has_trivial_destructor<Key>::value &&
boost::has_trivial_destructor<Value>::value),
template<typename> class Atom = std::atomic,
- typename Allocator = folly::detail::MMapAlloc,
- typename IndexType = uint32_t>
+ typename IndexType = uint32_t,
+ typename Allocator = folly::detail::MMapAlloc>
struct AtomicUnorderedInsertMap {
}
// post-increment
- ConstIterator operator++ (int dummy) {
+ ConstIterator operator++(int /* dummy */) {
auto prev = *this;
++*this;
return prev;
const Allocator& alloc = Allocator())
: allocator_(alloc)
{
- size_t capacity = maxSize / std::max(1.0f, maxLoadFactor) + 128;
+ size_t capacity = size_t(maxSize / std::min(1.0f, maxLoadFactor) + 128);
size_t avail = size_t{1} << (8 * sizeof(IndexType) - 2);
if (capacity > avail && maxSize < avail) {
// we'll do our best
}
private:
-
- enum {
+ enum : IndexType {
kMaxAllocationTries = 1000, // after this we throw
};
/// Allocates a slot and returns its index. Tries to put it near
/// slots_[start].
IndexType allocateNear(IndexType start) {
- for (auto tries = 0; tries < kMaxAllocationTries; ++tries) {
+ for (IndexType tries = 0; tries < kMaxAllocationTries; ++tries) {
auto slot = allocationAttempt(start, tries);
auto prev = slots_[slot].headAndState_.load(std::memory_order_acquire);
if ((prev & 3) == EMPTY &&
/// can specialize it differently during deterministic testing
IndexType allocationAttempt(IndexType start, IndexType tries) const {
if (LIKELY(tries < 8 && start + tries < numSlots_)) {
- return start + tries;
+ return IndexType(start + tries);
} else {
IndexType rv;
if (sizeof(IndexType) <= 4) {
- rv = folly::Random::rand32(numSlots_);
+ rv = IndexType(folly::Random::rand32(numSlots_));
} else {
- rv = folly::Random::rand64(numSlots_);
+ rv = IndexType(folly::Random::rand64(numSlots_));
}
assert(rv < numSlots_);
return rv;
KeyEqual,
SkipKeyValueDeletion,
Atom,
- Allocator,
- uint64_t>;
-
+ uint64_t,
+ Allocator>;
/// MutableAtom is a tiny wrapper than gives you the option of atomically
/// updating values inserted into an AtomicUnorderedInsertMap<K,
}
-#endif