From 8f067460513430d78c3d84745d060f342545bee1 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 30 Apr 2014 10:45:58 -0700 Subject: [PATCH] Implement GetThreadCount on Linux, fix warnings. --- gtest/gtest-all.cc | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/gtest/gtest-all.cc b/gtest/gtest-all.cc index 5ced66a9..0ae139c6 100644 --- a/gtest/gtest-all.cc +++ b/gtest/gtest-all.cc @@ -601,7 +601,6 @@ class GTestFlagSaver { bool list_tests_; String output_; bool print_time_; - bool pretty_; internal::Int32 random_seed_; internal::Int32 repeat_; bool shuffle_; @@ -7497,7 +7496,6 @@ namespace internal { // of them. const char kPathSeparator = '\\'; const char kAlternatePathSeparator = '/'; -const char kPathSeparatorString[] = "\\"; const char kAlternatePathSeparatorString[] = "/"; # if GTEST_OS_WINDOWS_MOBILE // Windows CE doesn't have a current directory. You should not use @@ -7511,7 +7509,6 @@ const char kCurrentDirectoryString[] = ".\\"; # endif // GTEST_OS_WINDOWS_MOBILE #else const char kPathSeparator = '/'; -const char kPathSeparatorString[] = "/"; const char kCurrentDirectoryString[] = "./"; #endif // GTEST_OS_WINDOWS @@ -7849,6 +7846,7 @@ void FilePath::Normalize() { # include # include #else +# include # include #endif // GTEST_OS_WINDOWS_MOBILE @@ -7900,6 +7898,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() {