test/TestUtils.h \
ThreadCachedArena.h \
ThreadCachedInt.h \
+ ThreadId.h \
ThreadLocal.h \
ThreadName.h \
TimeoutQueue.h \
--- /dev/null
+/*
+ * Copyright 2016 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <cstdint>
+
+#include <pthread.h>
+
+namespace folly {
+
+inline uint64_t getCurrentThreadID() {
+#ifdef _WIN32
+ // There's no need to force a Windows.h include, so grab the ID
+ // via pthread instead.
+ return uint64_t(pthread_getw32threadid_np(pthread_self()));
+#else
+ return uint64_t(pthread_self());
+#endif
+}
+}
#include <folly/Benchmark.h>
#include <folly/Hash.h>
+#include <folly/ThreadId.h>
#include <folly/portability/GFlags.h>
#include <folly/portability/GTest.h>
std::atomic<int64_t> ints_[kBuckets_];
inline void inc(int64_t val = 1) {
- int bucket = hash::twang_mix64(
- uint64_t(pthread_self())) & (kBuckets_ - 1);
- std::atomic_fetch_add(&ints_[bucket], val);
+ int buck = hash::twang_mix64(folly::getCurrentThreadID()) & (kBuckets_ - 1);
+ std::atomic_fetch_add(&ints_[buck], val);
}
// read the first few and extrapolate
#include <folly/Baton.h>
#include <folly/Memory.h>
+#include <folly/ThreadId.h>
#include <folly/experimental/io/FsUtil.h>
#include <folly/portability/GTest.h>
#include <folly/portability/Unistd.h>
private:
uint64_t val() const {
- return (idx_ << 40) | uint64_t(pthread_self());
+ return (idx_ << 40) | folly::getCurrentThreadID();
}
uint64_t idx_;
TEST(ThreadLocal, SharedLibrary) {
auto exe = fs::executable_path();
- auto lib = exe.parent_path() / "lib_thread_local_test.so";
+ auto lib = exe.parent_path() / "thread_local_test_lib.so";
auto handle = dlopen(lib.string().c_str(), RTLD_LAZY);
EXPECT_NE(nullptr, handle);