Commit d286efd3 authored by Victor Zverovich's avatar Victor Zverovich

Implement GetThreadCount on Linux.

parent 494f5342
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
# include <io.h> # include <io.h>
# include <sys/stat.h> # include <sys/stat.h>
#else #else
# include <dirent.h>
# include <unistd.h> # include <unistd.h>
#endif // GTEST_OS_WINDOWS_MOBILE #endif // GTEST_OS_WINDOWS_MOBILE
...@@ -98,6 +99,22 @@ size_t GetThreadCount() { ...@@ -98,6 +99,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 #else
size_t GetThreadCount() { size_t GetThreadCount() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment