From: Adam Simpkins Date: Tue, 6 Jun 2017 17:22:59 +0000 (-0700) Subject: add missing include to ThreadId.h X-Git-Tag: v2017.06.12.00~35 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=14d85244f8b72912c44ff43ccdd5e55c0b84c9e2;p=folly.git add missing include to ThreadId.h Summary: The syscall() function is defined in apparently only defines IDs to be used with syscall(), but does not define the syscall() function itself. This caused build failures for files that included ThreadId.h before unistd.h Reviewed By: Orvid Differential Revision: D5189658 fbshipit-source-id: 2ec8ea1d58f3fc14cf458a53ecaa811978527398 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 22fbe680..479ff5ec 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -530,6 +530,7 @@ if (BUILD_TESTS) TEST synchronized_test SOURCES SynchronizedTest.cpp TEST thread_cached_arena_test SOURCES ThreadCachedArenaTest.cpp TEST thread_cached_int_test SOURCES ThreadCachedIntTest.cpp + TEST thread_id_test SOURCES ThreadIdTest.cpp TEST thread_local_test SOURCES ThreadLocalTest.cpp TEST thread_name_test SOURCES ThreadNameTest.cpp TEST timeout_queue_test SOURCES TimeoutQueueTest.cpp diff --git a/folly/ThreadId.h b/folly/ThreadId.h index 9896f874..18b82cd7 100644 --- a/folly/ThreadId.h +++ b/folly/ThreadId.h @@ -20,6 +20,7 @@ #include #include +#include #include namespace folly { diff --git a/folly/test/Makefile.am b/folly/test/Makefile.am index 60fdea58..1399315f 100644 --- a/folly/test/Makefile.am +++ b/folly/test/Makefile.am @@ -96,6 +96,9 @@ TESTS += fbstring_test_using_jemalloc thread_cached_int_test_SOURCES = ThreadCachedIntTest.cpp thread_cached_int_test_LDADD = libfollytestmain.la $(top_builddir)/libfollybenchmark.la +thread_id_test_SOURCES = ThreadIdTest.cpp +thread_id_test_LDADD = libfollytestmain.la + thread_local_test_SOURCES = ThreadLocalTest.cpp thread_local_test_LDADD = libfollytestmain.la $(top_builddir)/libfollybenchmark.la thread_local_test_LDFLAGS = -ldl diff --git a/folly/test/ThreadIdTest.cpp b/folly/test/ThreadIdTest.cpp new file mode 100644 index 00000000..88e6fac4 --- /dev/null +++ b/folly/test/ThreadIdTest.cpp @@ -0,0 +1,40 @@ +/* + * 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. + * 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. + */ + +// Make sure we include ThreadId.h before anything else. +// There is no ThreadId.cpp file, so this test is the only thing that verifies +// that ThreadId.h compiles by itself when included first. +#include + +#include + +#include + +TEST(ThreadId, getCurrentID) { + auto thisThreadID = folly::getCurrentThreadID(); + uint64_t otherThreadID; + std::thread otherThread{[&] { otherThreadID = folly::getCurrentThreadID(); }}; + otherThread.join(); + EXPECT_NE(thisThreadID, otherThreadID); +} + +TEST(ThreadId, getOSThreadID) { + auto thisThreadID = folly::getOSThreadID(); + uint64_t otherThreadID; + std::thread otherThread{[&] { otherThreadID = folly::getOSThreadID(); }}; + otherThread.join(); + EXPECT_NE(thisThreadID, otherThreadID); +}