Index: sandbox/linux/services/thread_helpers.cc |
diff --git a/sandbox/linux/services/thread_helpers.cc b/sandbox/linux/services/thread_helpers.cc |
index e0794f84a4416935c26e28f7c0ac0edaa3e11dc8..e820449cb703607862da639f604b7134c22b79d8 100644 |
--- a/sandbox/linux/services/thread_helpers.cc |
+++ b/sandbox/linux/services/thread_helpers.cc |
@@ -5,6 +5,7 @@ |
#include "sandbox/linux/services/thread_helpers.h" |
#include <errno.h> |
+#include <fcntl.h> |
#include <signal.h> |
#include <sys/types.h> |
#include <sys/stat.h> |
@@ -21,7 +22,9 @@ |
namespace sandbox { |
-bool ThreadHelpers::IsSingleThreaded(int proc_self_task) { |
+namespace { |
+ |
+bool IsSingleThreadedImpl(int proc_self_task) { |
CHECK_LE(0, proc_self_task); |
struct stat task_stat; |
int fstat_ret = fstat(proc_self_task, &task_stat); |
@@ -35,6 +38,21 @@ bool ThreadHelpers::IsSingleThreaded(int proc_self_task) { |
return task_stat.st_nlink == 3; |
} |
+} // namespace |
+ |
+bool ThreadHelpers::IsSingleThreaded(int proc_self_task) { |
+ DCHECK_LE(-1, proc_self_task); |
+ if (-1 == proc_self_task) { |
+ const int task_fd = open("/proc/self/task/", O_RDONLY | O_DIRECTORY); |
+ PCHECK(0 <= task_fd); |
+ const bool result = IsSingleThreadedImpl(task_fd); |
+ PCHECK(0 == IGNORE_EINTR(close(task_fd))); |
+ return result; |
+ } else { |
+ return IsSingleThreadedImpl(proc_self_task); |
+ } |
+} |
+ |
bool ThreadHelpers::StopThreadAndWatchProcFS(int proc_self_task, |
base::Thread* thread) { |
DCHECK_LE(0, proc_self_task); |