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 {
threadlocal_detail::StaticMeta<Tag>& 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<Tag>::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
......
......@@ -166,8 +166,8 @@ struct StaticMeta {
return *inst_;
}
int nextId_;
std::vector<int> freeIds_;
uint32_t nextId_;
std::vector<uint32_t> 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<std::mutex> 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);
......
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