add missing include to ThreadId.h
authorAdam Simpkins <simpkins@fb.com>
Tue, 6 Jun 2017 17:22:59 +0000 (10:22 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Tue, 6 Jun 2017 17:25:00 +0000 (10:25 -0700)
Summary:
The syscall() function is defined in <unistd.h>
<sys/syscall.h> 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

CMakeLists.txt
folly/ThreadId.h
folly/test/Makefile.am
folly/test/ThreadIdTest.cpp [new file with mode: 0644]

index 22fbe680b660b8a23dbf866c6b33cf44de2ac25a..479ff5ece5e9862b41e7da011e04da8b46fddffa 100755 (executable)
@@ -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
index 9896f8746b839ed433c992311e0a5b055623fc03..18b82cd7d7fec66afcd8751877eca8b5dd39fc88 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <folly/portability/PThread.h>
 #include <folly/portability/SysSyscall.h>
+#include <folly/portability/Unistd.h>
 #include <folly/portability/Windows.h>
 
 namespace folly {
index 60fdea584dbb9142c928fda43286d9311ae7f351..1399315f2aa7fd2a8a86e431b50665414de9b104 100644 (file)
@@ -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 (file)
index 0000000..88e6fac
--- /dev/null
@@ -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 <folly/ThreadId.h>
+
+#include <thread>
+
+#include <folly/portability/GTest.h>
+
+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);
+}