From 2bda6641d6a803545b43af65228cb94fdbf32d78 Mon Sep 17 00:00:00 2001 From: Sean Cannella Date: Fri, 5 Dec 2014 17:14:52 -0800 Subject: [PATCH] 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 --- folly/ThreadLocal.h | 6 +++--- folly/detail/ThreadLocalDetail.h | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/folly/ThreadLocal.h b/folly/ThreadLocal.h index 78a26979..5b518c93 100644 --- a/folly/ThreadLocal.h +++ b/folly/ThreadLocal.h @@ -210,7 +210,7 @@ class ThreadLocalPtr { threadlocal_detail::StaticMeta& meta_; std::mutex* lock_; - int id_; + uint32_t id_; public: class Iterator; @@ -309,7 +309,7 @@ class ThreadLocalPtr { } private: - explicit Accessor(int id) + explicit Accessor(uint32_t id) : meta_(threadlocal_detail::StaticMeta::instance()), lock_(&meta_.lock_) { lock_->lock(); @@ -344,7 +344,7 @@ class ThreadLocalPtr { ThreadLocalPtr(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 diff --git a/folly/detail/ThreadLocalDetail.h b/folly/detail/ThreadLocalDetail.h index 0c05802c..6b7a2944 100644 --- a/folly/detail/ThreadLocalDetail.h +++ b/folly/detail/ThreadLocalDetail.h @@ -166,8 +166,8 @@ struct StaticMeta { return *inst_; } - int nextId_; - std::vector freeIds_; + uint32_t nextId_; + std::vector freeIds_; std::mutex lock_; pthread_key_t pthreadKey_; ThreadEntry head_; @@ -281,8 +281,8 @@ struct StaticMeta { #endif } - static int create() { - int id; + static uint32_t create() { + uint32_t id; auto & meta = instance(); std::lock_guard g(meta.lock_); if (!meta.freeIds_.empty()) { @@ -294,7 +294,7 @@ struct StaticMeta { return id; } - static void destroy(size_t id) { + static void destroy(uint32_t id) { try { auto & meta = instance(); // Elements in other threads that use this id. @@ -336,7 +336,7 @@ struct StaticMeta { * Reserve enough space in the ThreadEntry::elements for the item * @id to fit in. */ - static void reserve(int id) { + static void reserve(uint32_t id) { auto& meta = instance(); ThreadEntry* threadEntry = getThreadEntry(); size_t prevCapacity = threadEntry->elementsCapacity; @@ -422,7 +422,7 @@ struct StaticMeta { #endif } - static ElementWrapper& get(size_t id) { + static ElementWrapper& get(uint32_t id) { ThreadEntry* threadEntry = getThreadEntry(); if (UNLIKELY(threadEntry->elementsCapacity <= id)) { reserve(id); -- 2.34.1