X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FIndexedMemPool.h;h=3a7524e1219ef46ed344d3eb889001fe1e48e543;hb=b0c9ca0f0ebd6dd13d0e4a4525c862358c92fee1;hp=437685a23e657349cee5dd9c8e2ce51376242299;hpb=30e9f34e93579b255767fc1680c81fcd9c023ba9;p=folly.git diff --git a/folly/IndexedMemPool.h b/folly/IndexedMemPool.h index 437685a2..3a7524e1 100644 --- a/folly/IndexedMemPool.h +++ b/folly/IndexedMemPool.h @@ -1,5 +1,5 @@ /* - * 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. @@ -14,17 +14,17 @@ * limitations under the License. */ -#ifndef FOLLY_INDEXEDMEMPOOL_H -#define FOLLY_INDEXEDMEMPOOL_H +#pragma once #include -#include #include -#include -#include +#include +#include #include #include #include +#include +#include // Ignore shadowing warnings within this file, so includers can use -Wshadow. #pragma GCC diagnostic push @@ -113,8 +113,9 @@ struct IndexedMemPool : boost::noncopyable { static constexpr uint32_t maxIndexForCapacity(uint32_t capacity) { // index of uint32_t(-1) == UINT32_MAX is reserved for isAllocated tracking - return std::min(uint64_t(capacity) + (NumLocalLists - 1) * LocalListLimit, - uint64_t(uint32_t(-1) - 1)); + return uint32_t(std::min( + uint64_t(capacity) + (NumLocalLists - 1) * LocalListLimit, + uint64_t(uint32_t(-1) - 1))); } static constexpr uint32_t capacityForMaxIndex(uint32_t maxIndex) { @@ -130,7 +131,7 @@ struct IndexedMemPool : boost::noncopyable { , globalHead_(TaggedPtr{}) { const size_t needed = sizeof(Slot) * (actualCapacity_ + 1); - long pagesize = sysconf(_SC_PAGESIZE); + size_t pagesize = sysconf(_SC_PAGESIZE); mmapLength_ = ((needed - 1) & ~(pagesize - 1)) + pagesize; assert(needed <= mmapLength_ && mmapLength_ < needed + pagesize); assert((mmapLength_ % pagesize) == 0); @@ -218,7 +219,7 @@ struct IndexedMemPool : boost::noncopyable { auto slot = reinterpret_cast( reinterpret_cast(elem) - offsetof(Slot, elem)); - auto rv = slot - slots_; + auto rv = uint32_t(slot - slots_); // this assert also tests that rv is in range assert(elem == &(*this)[rv]); @@ -310,7 +311,7 @@ struct IndexedMemPool : boost::noncopyable { /// raw storage, only 1..min(size_,actualCapacity_) (inclusive) are /// actually constructed. Note that slots_[0] is not constructed or used - Slot* FOLLY_ALIGN_TO_AVOID_FALSE_SHARING slots_; + FOLLY_ALIGN_TO_AVOID_FALSE_SHARING Slot* slots_; /// use AccessSpreader to find your list. We use stripes instead of /// thread-local to avoid the need to grow or shrink on thread start @@ -319,7 +320,7 @@ struct IndexedMemPool : boost::noncopyable { /// this is the head of a list of node chained by globalNext, that are /// themselves each the head of a list chained by localNext - AtomicStruct FOLLY_ALIGN_TO_AVOID_FALSE_SHARING globalHead_; + FOLLY_ALIGN_TO_AVOID_FALSE_SHARING AtomicStruct globalHead_; ///////////// private methods @@ -466,4 +467,3 @@ struct IndexedMemPoolRecycler { } // namespace folly # pragma GCC diagnostic pop -#endif