diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-13 22:23:53 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-13 22:23:53 +0000 |
commit | 89dd4eed72dfea6912684540a65842ad01773aa6 (patch) | |
tree | 7d7d01a3877ec1b6e7424fc1aeb03b10e855bea6 /chrome/common/process_watcher_posix.cc | |
parent | 706ab7f69fe1f8bd46d3341bf2709a93664c724d (diff) | |
download | chromium_src-89dd4eed72dfea6912684540a65842ad01773aa6.zip chromium_src-89dd4eed72dfea6912684540a65842ad01773aa6.tar.gz chromium_src-89dd4eed72dfea6912684540a65842ad01773aa6.tar.bz2 |
Additional svn ignores for native_client and Makefile.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20553 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/process_watcher_posix.cc')
-rw-r--r-- | chrome/common/process_watcher_posix.cc | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/chrome/common/process_watcher_posix.cc b/chrome/common/process_watcher_posix.cc index f1ae4f4..a583fde 100644 --- a/chrome/common/process_watcher_posix.cc +++ b/chrome/common/process_watcher_posix.cc @@ -30,8 +30,9 @@ static bool IsChildDead(pid_t child) { // If the child doesn't exit within a couple of seconds, kill it. class BackgroundReaper : public PlatformThread::Delegate { public: - explicit BackgroundReaper(pid_t child) - : child_(child) { + explicit BackgroundReaper(pid_t child, unsigned timeout) + : child_(child), + timeout_(timeout) { } void ThreadMain() { @@ -43,8 +44,17 @@ class BackgroundReaper : public PlatformThread::Delegate { // There's no good way to wait for a specific child to exit in a timed // fashion. (No kqueue on Linux), so we just loop and sleep. - // Waits 0.5 * 4 = 2 seconds. - for (unsigned i = 0; i < 4; ++i) { + // Wait forever case. + if (timeout_ == 0) { + while (1) { + PlatformThread::Sleep(5000); // 5 seconds, not in a hurry. + if (IsChildDead(child_)) + return; + } + } + + // Waits 0.5 * timeout_ seconds + for (unsigned i = 0; i < timeout_; ++i) { PlatformThread::Sleep(500); // 0.5 seconds if (IsChildDead(child_)) return; @@ -62,6 +72,9 @@ class BackgroundReaper : public PlatformThread::Delegate { private: const pid_t child_; + // Number of 0.5 seconds intervals to wait, if 0 then wait forever and do + // not attempt to kill |child_|. + const unsigned timeout_; DISALLOW_COPY_AND_ASSIGN(BackgroundReaper); }; @@ -72,6 +85,17 @@ void ProcessWatcher::EnsureProcessTerminated(base::ProcessHandle process) { if (IsChildDead(process)) return; - BackgroundReaper* reaper = new BackgroundReaper(process); + const unsigned timeout = 4; // 4 * 0.5 seconds = 2 seconds + BackgroundReaper* reaper = new BackgroundReaper(process, timeout); + PlatformThread::CreateNonJoinable(0, reaper); +} + +// static +void ProcessWatcher::EnsureProcessGetsReaped(base::ProcessHandle process) { + // If the child is already dead, then there's nothing to do + if (IsChildDead(process)) + return; + + BackgroundReaper* reaper = new BackgroundReaper(process, 0); PlatformThread::CreateNonJoinable(0, reaper); } |