Skip to content

Commit 23989c2

Browse files
committed
Merged base/time files from chromium upstream.
Added thread-specific CPU-time feature, needed for performance log support. issue: #1
1 parent 6968ac0 commit 23989c2

File tree

13 files changed

+1366
-362
lines changed

13 files changed

+1366
-362
lines changed

base.gyp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@
205205
'src/base/mac/foundation_util.mm',
206206
'src/base/mac/bundle_locations.mm',
207207
'src/base/mac/mac_logging.cc',
208+
'src/base/mac/mach_logging.cc',
209+
'src/base/mac/scoped_mach_port.cc',
208210
'src/base/threading/platform_thread_mac.mm',
209211
'src/base/time_mac.cc',
210212
],

inc/base/float_util.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,24 @@
1212

1313
namespace base {
1414

15-
inline bool IsFinite(const double& number) {
16-
#if defined(OS_ANDROID)
17-
// isfinite isn't available on Android: http://b.android.com/34793
18-
return finite(number) != 0;
19-
#elif defined(OS_POSIX)
15+
template <typename Float>
16+
inline bool IsFinite(const Float& number) {
17+
#if defined(OS_POSIX)
2018
return isfinite(number) != 0;
2119
#elif defined(OS_WIN)
2220
return _finite(number) != 0;
2321
#endif
2422
}
2523

24+
template <typename Float>
25+
inline bool IsNaN(const Float& number) {
26+
#if defined(OS_POSIX)
27+
return isnan(number) != 0;
28+
#elif defined(OS_WIN)
29+
return _isnan(number) != 0;
30+
#endif
31+
}
32+
2633
} // namespace base
2734

2835
#endif // BASE_FLOAT_UTIL_H_

inc/base/mac/mach_logging.h

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
// Copyright 2014 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef BASE_MAC_MACH_LOGGING_H_
6+
#define BASE_MAC_MACH_LOGGING_H_
7+
8+
#include <mach/mach.h>
9+
10+
#include "base/base_export.h"
11+
#include "base/basictypes.h"
12+
#include "base/logging.h"
13+
#include "build/build_config.h"
14+
15+
// Use the MACH_LOG family of macros along with a mach_error_t (kern_return_t)
16+
// containing a Mach error. The error value will be decoded so that logged
17+
// messages explain the error.
18+
//
19+
// Use the BOOTSTRAP_LOG family of macros specifically for errors that occur
20+
// while interoperating with the bootstrap subsystem. These errors will first
21+
// be looked up as bootstrap error messages. If no match is found, they will
22+
// be treated as generic Mach errors, as in MACH_LOG.
23+
//
24+
// Examples:
25+
//
26+
// kern_return_t kr = mach_timebase_info(&info);
27+
// if (kr != KERN_SUCCESS) {
28+
// MACH_LOG(ERROR, kr) << "mach_timebase_info";
29+
// }
30+
//
31+
// kr = vm_deallocate(task, address, size);
32+
// MACH_DCHECK(kr == KERN_SUCCESS, kr) << "vm_deallocate";
33+
34+
namespace logging {
35+
36+
class BASE_EXPORT MachLogMessage : public logging::LogMessage {
37+
public:
38+
MachLogMessage(const char* file_path,
39+
int line,
40+
LogSeverity severity,
41+
mach_error_t mach_err);
42+
~MachLogMessage();
43+
44+
private:
45+
mach_error_t mach_err_;
46+
47+
DISALLOW_COPY_AND_ASSIGN(MachLogMessage);
48+
};
49+
50+
} // namespace logging
51+
52+
#if defined(NDEBUG)
53+
#define MACH_DVLOG_IS_ON(verbose_level) 0
54+
#else
55+
#define MACH_DVLOG_IS_ON(verbose_level) VLOG_IS_ON(verbose_level)
56+
#endif
57+
58+
#define MACH_LOG_STREAM(severity, mach_err) \
59+
COMPACT_GOOGLE_LOG_EX_ ## severity(MachLogMessage, mach_err).stream()
60+
#define MACH_VLOG_STREAM(verbose_level, mach_err) \
61+
logging::MachLogMessage(__FILE__, __LINE__, \
62+
-verbose_level, mach_err).stream()
63+
64+
#define MACH_LOG(severity, mach_err) \
65+
LAZY_STREAM(MACH_LOG_STREAM(severity, mach_err), LOG_IS_ON(severity))
66+
#define MACH_LOG_IF(severity, condition, mach_err) \
67+
LAZY_STREAM(MACH_LOG_STREAM(severity, mach_err), \
68+
LOG_IS_ON(severity) && (condition))
69+
70+
#define MACH_VLOG(verbose_level, mach_err) \
71+
LAZY_STREAM(MACH_VLOG_STREAM(verbose_level, mach_err), \
72+
VLOG_IS_ON(verbose_level))
73+
#define MACH_VLOG_IF(verbose_level, condition, mach_err) \
74+
LAZY_STREAM(MACH_VLOG_STREAM(verbose_level, mach_err), \
75+
VLOG_IS_ON(verbose_level) && (condition))
76+
77+
#define MACH_CHECK(condition, mach_err) \
78+
LAZY_STREAM(MACH_LOG_STREAM(FATAL, mach_err), !(condition)) \
79+
<< "Check failed: " # condition << ". "
80+
81+
#define MACH_DLOG(severity, mach_err) \
82+
LAZY_STREAM(MACH_LOG_STREAM(severity, mach_err), DLOG_IS_ON(severity))
83+
#define MACH_DLOG_IF(severity, condition, mach_err) \
84+
LAZY_STREAM(MACH_LOG_STREAM(severity, mach_err), \
85+
DLOG_IS_ON(severity) && (condition))
86+
87+
#define MACH_DVLOG(verbose_level, mach_err) \
88+
LAZY_STREAM(MACH_VLOG_STREAM(verbose_level, mach_err), \
89+
MACH_DVLOG_IS_ON(verbose_level))
90+
#define MACH_DVLOG_IF(verbose_level, condition, mach_err) \
91+
LAZY_STREAM(MACH_VLOG_STREAM(verbose_level, mach_err), \
92+
MACH_DVLOG_IS_ON(verbose_level) && (condition))
93+
94+
#define MACH_DCHECK(condition, mach_err) \
95+
LAZY_STREAM(MACH_LOG_STREAM(FATAL, mach_err), \
96+
DCHECK_IS_ON() && !(condition)) \
97+
<< "Check failed: " #condition << ". "
98+
99+
#if !defined(OS_IOS)
100+
101+
namespace logging {
102+
103+
class BASE_EXPORT BootstrapLogMessage : public logging::LogMessage {
104+
public:
105+
BootstrapLogMessage(const char* file_path,
106+
int line,
107+
LogSeverity severity,
108+
kern_return_t bootstrap_err);
109+
~BootstrapLogMessage();
110+
111+
private:
112+
kern_return_t bootstrap_err_;
113+
114+
DISALLOW_COPY_AND_ASSIGN(BootstrapLogMessage);
115+
};
116+
117+
} // namespace logging
118+
119+
#define BOOTSTRAP_DVLOG_IS_ON MACH_DVLOG_IS_ON
120+
121+
#define BOOTSTRAP_LOG_STREAM(severity, bootstrap_err) \
122+
COMPACT_GOOGLE_LOG_EX_ ## severity(BootstrapLogMessage, \
123+
bootstrap_err).stream()
124+
#define BOOTSTRAP_VLOG_STREAM(verbose_level, bootstrap_err) \
125+
logging::BootstrapLogMessage(__FILE__, __LINE__, \
126+
-verbose_level, bootstrap_err).stream()
127+
128+
#define BOOTSTRAP_LOG(severity, bootstrap_err) \
129+
LAZY_STREAM(BOOTSTRAP_LOG_STREAM(severity, \
130+
bootstrap_err), LOG_IS_ON(severity))
131+
#define BOOTSTRAP_LOG_IF(severity, condition, bootstrap_err) \
132+
LAZY_STREAM(BOOTSTRAP_LOG_STREAM(severity, bootstrap_err), \
133+
LOG_IS_ON(severity) && (condition))
134+
135+
#define BOOTSTRAP_VLOG(verbose_level, bootstrap_err) \
136+
LAZY_STREAM(BOOTSTRAP_VLOG_STREAM(verbose_level, bootstrap_err), \
137+
VLOG_IS_ON(verbose_level))
138+
#define BOOTSTRAP_VLOG_IF(verbose_level, condition, bootstrap_err) \
139+
LAZY_STREAM(BOOTSTRAP_VLOG_STREAM(verbose_level, bootstrap_err), \
140+
VLOG_IS_ON(verbose_level) && (condition))
141+
142+
#define BOOTSTRAP_CHECK(condition, bootstrap_err) \
143+
LAZY_STREAM(BOOTSTRAP_LOG_STREAM(FATAL, bootstrap_err), !(condition)) \
144+
<< "Check failed: " # condition << ". "
145+
146+
#define BOOTSTRAP_DLOG(severity, bootstrap_err) \
147+
LAZY_STREAM(BOOTSTRAP_LOG_STREAM(severity, bootstrap_err), \
148+
DLOG_IS_ON(severity))
149+
#define BOOTSTRAP_DLOG_IF(severity, condition, bootstrap_err) \
150+
LAZY_STREAM(BOOTSTRAP_LOG_STREAM(severity, bootstrap_err), \
151+
DLOG_IS_ON(severity) && (condition))
152+
153+
#define BOOTSTRAP_DVLOG(verbose_level, bootstrap_err) \
154+
LAZY_STREAM(BOOTSTRAP_VLOG_STREAM(verbose_level, bootstrap_err), \
155+
BOOTSTRAP_DVLOG_IS_ON(verbose_level))
156+
#define BOOTSTRAP_DVLOG_IF(verbose_level, condition, bootstrap_err) \
157+
LAZY_STREAM(BOOTSTRAP_VLOG_STREAM(verbose_level, bootstrap_err), \
158+
BOOTSTRAP_DVLOG_IS_ON(verbose_level) && (condition))
159+
160+
#define BOOTSTRAP_DCHECK(condition, bootstrap_err) \
161+
LAZY_STREAM(BOOTSTRAP_LOG_STREAM(FATAL, bootstrap_err), \
162+
DCHECK_IS_ON() && !(condition)) \
163+
<< "Check failed: " #condition << ". "
164+
165+
#endif // !OS_IOS
166+
167+
#endif // BASE_MAC_MACH_LOGGING_H_

inc/base/mac/scoped_mach_port.h

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef BASE_MAC_SCOPED_MACH_PORT_H_
6+
#define BASE_MAC_SCOPED_MACH_PORT_H_
7+
8+
#include <mach/mach.h>
9+
10+
#include "base/base_export.h"
11+
#include "base/scoped_generic.h"
12+
13+
namespace base {
14+
namespace mac {
15+
16+
namespace internal {
17+
18+
struct BASE_EXPORT SendRightTraits {
19+
static mach_port_t InvalidValue() {
20+
return MACH_PORT_NULL;
21+
}
22+
23+
static void Free(mach_port_t port);
24+
};
25+
26+
struct BASE_EXPORT ReceiveRightTraits {
27+
static mach_port_t InvalidValue() {
28+
return MACH_PORT_NULL;
29+
}
30+
31+
static void Free(mach_port_t port);
32+
};
33+
34+
struct PortSetTraits {
35+
static mach_port_t InvalidValue() {
36+
return MACH_PORT_NULL;
37+
}
38+
39+
static void Free(mach_port_t port);
40+
};
41+
42+
} // namespace internal
43+
44+
// A scoper for handling a Mach port that names a send right. Send rights are
45+
// reference counted, and this takes ownership of the right on construction
46+
// and then removes a reference to the right on destruction. If the reference
47+
// is the last one on the right, the right is deallocated.
48+
class BASE_EXPORT ScopedMachSendRight :
49+
public base::ScopedGeneric<mach_port_t, internal::SendRightTraits> {
50+
public:
51+
explicit ScopedMachSendRight(mach_port_t port = traits_type::InvalidValue())
52+
: ScopedGeneric(port) {}
53+
54+
operator mach_port_t() const { return get(); }
55+
};
56+
57+
// A scoper for handling a Mach port's receive right. There is only one
58+
// receive right per port. This takes ownership of the receive right on
59+
// construction and then destroys the right on destruction, turning all
60+
// outstanding send rights into dead names.
61+
class BASE_EXPORT ScopedMachReceiveRight :
62+
public base::ScopedGeneric<mach_port_t, internal::ReceiveRightTraits> {
63+
public:
64+
explicit ScopedMachReceiveRight(
65+
mach_port_t port = traits_type::InvalidValue()) : ScopedGeneric(port) {}
66+
67+
operator mach_port_t() const { return get(); }
68+
};
69+
70+
// A scoper for handling a Mach port set. A port set can have only one
71+
// reference. This takes ownership of that single reference on construction and
72+
// destroys the port set on destruction. Destroying a port set does not destroy
73+
// the receive rights that are members of the port set.
74+
class BASE_EXPORT ScopedMachPortSet :
75+
public ScopedGeneric<mach_port_t, internal::PortSetTraits> {
76+
public:
77+
explicit ScopedMachPortSet(mach_port_t port = traits_type::InvalidValue())
78+
: ScopedGeneric(port) {}
79+
80+
operator mach_port_t() const { return get(); }
81+
};
82+
83+
} // namespace mac
84+
} // namespace base
85+
86+
#endif // BASE_MAC_SCOPED_MACH_PORT_H_

0 commit comments

Comments
 (0)