Commit 2bda6641 authored by Sean Cannella's avatar Sean Cannella Committed by Dave Watson

Make ThreadLocal identifiers consistent

Summary:
Implicitly bouncing between size_t and int for identifiers
causes problems when building on 64-bit iOS. Fix this.

Test Plan: fbmake runtests

Reviewed By: meyering@fb.com, njormrod@fb.com

Subscribers: trunkagent, njormrod, folly-diffs@, fma, kmdent, shikong, pgriess

FB internal diff: D1722061

Signature: t1:1722061:1417819039:8e3938cf8d4d241551ed3dd3978c1b11f57398c5
parent 96e52d24
...@@ -210,7 +210,7 @@ class ThreadLocalPtr { ...@@ -210,7 +210,7 @@ class ThreadLocalPtr {
threadlocal_detail::StaticMeta<Tag>& meta_; threadlocal_detail::StaticMeta<Tag>& meta_;
std::mutex* lock_; std::mutex* lock_;
int id_; uint32_t id_;
public: public:
class Iterator; class Iterator;
...@@ -309,7 +309,7 @@ class ThreadLocalPtr { ...@@ -309,7 +309,7 @@ class ThreadLocalPtr {
} }
private: private:
explicit Accessor(int id) explicit Accessor(uint32_t id)
: meta_(threadlocal_detail::StaticMeta<Tag>::instance()), : meta_(threadlocal_detail::StaticMeta<Tag>::instance()),
lock_(&meta_.lock_) { lock_(&meta_.lock_) {
lock_->lock(); lock_->lock();
...@@ -344,7 +344,7 @@ class ThreadLocalPtr { ...@@ -344,7 +344,7 @@ class ThreadLocalPtr {
ThreadLocalPtr(const ThreadLocalPtr&) = delete; ThreadLocalPtr(const ThreadLocalPtr&) = delete;
ThreadLocalPtr& operator=(const ThreadLocalPtr&) = delete; ThreadLocalPtr& operator=(const ThreadLocalPtr&) = delete;
int id_; // every instantiation has a unique id uint32_t id_; // every instantiation has a unique id
}; };
} // namespace folly } // namespace folly
......
...@@ -166,8 +166,8 @@ struct StaticMeta { ...@@ -166,8 +166,8 @@ struct StaticMeta {
return *inst_; return *inst_;
} }
int nextId_; uint32_t nextId_;
std::vector<int> freeIds_; std::vector<uint32_t> freeIds_;
std::mutex lock_; std::mutex lock_;
pthread_key_t pthreadKey_; pthread_key_t pthreadKey_;
ThreadEntry head_; ThreadEntry head_;
...@@ -281,8 +281,8 @@ struct StaticMeta { ...@@ -281,8 +281,8 @@ struct StaticMeta {
#endif #endif
} }
static int create() { static uint32_t create() {
int id; uint32_t id;
auto & meta = instance(); auto & meta = instance();
std::lock_guard<std::mutex> g(meta.lock_); std::lock_guard<std::mutex> g(meta.lock_);
if (!meta.freeIds_.empty()) { if (!meta.freeIds_.empty()) {
...@@ -294,7 +294,7 @@ struct StaticMeta { ...@@ -294,7 +294,7 @@ struct StaticMeta {
return id; return id;
} }
static void destroy(size_t id) { static void destroy(uint32_t id) {
try { try {
auto & meta = instance(); auto & meta = instance();
// Elements in other threads that use this id. // Elements in other threads that use this id.
...@@ -336,7 +336,7 @@ struct StaticMeta { ...@@ -336,7 +336,7 @@ struct StaticMeta {
* Reserve enough space in the ThreadEntry::elements for the item * Reserve enough space in the ThreadEntry::elements for the item
* @id to fit in. * @id to fit in.
*/ */
static void reserve(int id) { static void reserve(uint32_t id) {
auto& meta = instance(); auto& meta = instance();
ThreadEntry* threadEntry = getThreadEntry(); ThreadEntry* threadEntry = getThreadEntry();
size_t prevCapacity = threadEntry->elementsCapacity; size_t prevCapacity = threadEntry->elementsCapacity;
...@@ -422,7 +422,7 @@ struct StaticMeta { ...@@ -422,7 +422,7 @@ struct StaticMeta {
#endif #endif
} }
static ElementWrapper& get(size_t id) { static ElementWrapper& get(uint32_t id) {
ThreadEntry* threadEntry = getThreadEntry(); ThreadEntry* threadEntry = getThreadEntry();
if (UNLIKELY(threadEntry->elementsCapacity <= id)) { if (UNLIKELY(threadEntry->elementsCapacity <= id)) {
reserve(id); reserve(id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment