From 44e23c39f1c9b8fc5b05291baab6441f05dc0704 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 7 Aug 2014 09:30:46 -0700 Subject: [PATCH] Implement GetThreadCount on Linux. --- gtest/gtest-all.cc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/gtest/gtest-all.cc b/gtest/gtest-all.cc index a9a03b2e..7c858630 100644 --- a/gtest/gtest-all.cc +++ b/gtest/gtest-all.cc @@ -8258,6 +8258,7 @@ void FilePath::Normalize() { # include #else # include +# include #endif // GTEST_OS_WINDOWS_MOBILE #if GTEST_OS_MAC @@ -8333,6 +8334,22 @@ size_t GetThreadCount() { } } +#elif GTEST_OS_LINUX + +// Returns the number of threads running in the process, or 0 to indicate that +// we cannot detect it. +size_t GetThreadCount() { + size_t thread_count = 0; + if (DIR *dir = opendir("/proc/self/task")) { + while (dirent *entry = readdir(dir)) { + if (entry->d_name[0] != '.') + ++thread_count; + } + closedir(dir); + } + return thread_count; +} + #else size_t GetThreadCount() {