summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-15 11:55:08 +0000
committerjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-15 11:55:08 +0000
commite36e86f9cf568e12a47cc779893580a09b08803a (patch)
treebabbda83fb63c64565309a8fd19782f1145c72ce /base
parent86e19d84402a76c57fce85655c24f547312b6084 (diff)
downloadchromium_src-e36e86f9cf568e12a47cc779893580a09b08803a.zip
chromium_src-e36e86f9cf568e12a47cc779893580a09b08803a.tar.gz
chromium_src-e36e86f9cf568e12a47cc779893580a09b08803a.tar.bz2
Make ProcessWatcher use kqueues on Mac.
* Port ProcessWatcher::EnsureProcessTerminated() to kqueue() APIs on OS X. * Make ProcessWatcher::EnsureProcessGetsReaped() Linux-only, since it's only used there. * Add a unit test. BUG=12731 TEST=Open Chrome/Mac, open and close a few tabs. Processes shouldn't stay around. Review URL: http://codereview.chromium.org/496007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34547 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/base.gypi1
-rw-r--r--base/file_util.h14
-rw-r--r--base/time.h4
-rw-r--r--base/time_posix.cc16
-rw-r--r--base/time_unittest.cc21
5 files changed, 55 insertions, 1 deletions
diff --git a/base/base.gypi b/base/base.gypi
index 77a919e..0c076d4 100644
--- a/base/base.gypi
+++ b/base/base.gypi
@@ -287,7 +287,6 @@
'message_pump_glib.cc',
'nss_init.cc',
'nss_init.h',
- 'time_posix.cc',
],
},],
[ 'OS != "linux"', {
diff --git a/base/file_util.h b/base/file_util.h
index 9eb1729..543a86c 100644
--- a/base/file_util.h
+++ b/base/file_util.h
@@ -371,6 +371,20 @@ class ScopedFILEClose {
typedef scoped_ptr_malloc<FILE, ScopedFILEClose> ScopedFILE;
+#if defined(OS_POSIX)
+// A class to handle auto-closing of FDs.
+class ScopedFDClose {
+ public:
+ inline void operator()(int* x) const {
+ if (x) {
+ close(*x);
+ }
+ }
+};
+
+typedef scoped_ptr_malloc<int, ScopedFDClose> ScopedFD;
+#endif // OS_POSIX
+
// A class for enumerating the files in a provided path. The order of the
// results is not guaranteed.
//
diff --git a/base/time.h b/base/time.h
index 33ab227..538659d 100644
--- a/base/time.h
+++ b/base/time.h
@@ -62,6 +62,10 @@ class TimeDelta {
return delta_;
}
+#if defined(OS_POSIX)
+ struct timespec ToTimeSpec() const;
+#endif
+
// Returns the time delta in some unit. The F versions return a floating
// point value, the "regular" versions return a rounded-down value.
//
diff --git a/base/time_posix.cc b/base/time_posix.cc
index c64f8e7..af7ee25 100644
--- a/base/time_posix.cc
+++ b/base/time_posix.cc
@@ -14,6 +14,7 @@
namespace base {
+#if !defined(OS_MACOSX)
// The Time routines in this file use standard POSIX routines, or almost-
// standard routines in the case of timegm. We need to use a Mach-specific
// function for TimeTicks::Now() on Mac OS X.
@@ -174,4 +175,19 @@ TimeTicks TimeTicks::HighResNow() {
return Now();
}
+#endif // !OS_MACOSX
+
+struct timespec TimeDelta::ToTimeSpec() const {
+ int64 microseconds = InMicroseconds();
+ time_t seconds = 0;
+ if (microseconds >= Time::kMicrosecondsPerSecond) {
+ seconds = InSeconds();
+ microseconds -= seconds * Time::kMicrosecondsPerSecond;
+ }
+ struct timespec result =
+ {seconds,
+ microseconds * Time::kNanosecondsPerMicrosecond};
+ return result;
+}
+
} // namespace base
diff --git a/base/time_unittest.cc b/base/time_unittest.cc
index 81daab0..76b357a 100644
--- a/base/time_unittest.cc
+++ b/base/time_unittest.cc
@@ -142,6 +142,27 @@ TEST(TimeDelta, FromAndIn) {
EXPECT_EQ(13, TimeDelta::FromMicroseconds(13).InMicroseconds());
}
+#if defined(OS_POSIX)
+TEST(TimeDelta, TimeSpecConversion) {
+ struct timespec result = TimeDelta::FromSeconds(0).ToTimeSpec();
+ EXPECT_EQ(result.tv_sec, 0);
+ EXPECT_EQ(result.tv_nsec, 0);
+
+ result = TimeDelta::FromSeconds(1).ToTimeSpec();
+ EXPECT_EQ(result.tv_sec, 1);
+ EXPECT_EQ(result.tv_nsec, 0);
+
+ result = TimeDelta::FromMicroseconds(1).ToTimeSpec();
+ EXPECT_EQ(result.tv_sec, 0);
+ EXPECT_EQ(result.tv_nsec, 1000);
+
+ result = TimeDelta::FromMicroseconds(
+ Time::kMicrosecondsPerSecond + 1).ToTimeSpec();
+ EXPECT_EQ(result.tv_sec, 1);
+ EXPECT_EQ(result.tv_nsec, 1000);
+}
+#endif // OS_POSIX
+
// Our internal time format is serialized in things like databases, so it's
// important that it's consistent across all our platforms. We use the 1601
// Windows epoch as the internal format across all platforms.