Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: src/base/platform/time.h

Issue 2381273002: Turn libbase into a component (Closed)
Patch Set: updates Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/base/platform/semaphore.h ('k') | src/base/sys-info.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_BASE_PLATFORM_TIME_H_ 5 #ifndef V8_BASE_PLATFORM_TIME_H_
6 #define V8_BASE_PLATFORM_TIME_H_ 6 #define V8_BASE_PLATFORM_TIME_H_
7 7
8 #include <ctime> 8 #include <ctime>
9 #include <iosfwd> 9 #include <iosfwd>
10 #include <limits> 10 #include <limits>
11 11
12 #include "src/base/base-export.h"
12 #include "src/base/bits.h" 13 #include "src/base/bits.h"
13 #include "src/base/macros.h" 14 #include "src/base/macros.h"
14 #include "src/base/safe_math.h" 15 #include "src/base/safe_math.h"
15 #if V8_OS_WIN 16 #if V8_OS_WIN
16 #include "src/base/win32-headers.h" 17 #include "src/base/win32-headers.h"
17 #endif 18 #endif
18 19
19 // Forward declarations. 20 // Forward declarations.
20 extern "C" { 21 extern "C" {
21 struct _FILETIME; 22 struct _FILETIME;
(...skipping 13 matching lines...) Expand all
35 template<class TimeClass> 36 template<class TimeClass>
36 class TimeBase; 37 class TimeBase;
37 } 38 }
38 39
39 // ----------------------------------------------------------------------------- 40 // -----------------------------------------------------------------------------
40 // TimeDelta 41 // TimeDelta
41 // 42 //
42 // This class represents a duration of time, internally represented in 43 // This class represents a duration of time, internally represented in
43 // microseonds. 44 // microseonds.
44 45
45 class TimeDelta final { 46 class V8_BASE_EXPORT TimeDelta final {
46 public: 47 public:
47 TimeDelta() : delta_(0) {} 48 TimeDelta() : delta_(0) {}
48 49
49 // Converts units of time to TimeDeltas. 50 // Converts units of time to TimeDeltas.
50 static TimeDelta FromDays(int days); 51 static TimeDelta FromDays(int days);
51 static TimeDelta FromHours(int hours); 52 static TimeDelta FromHours(int hours);
52 static TimeDelta FromMinutes(int minutes); 53 static TimeDelta FromMinutes(int minutes);
53 static TimeDelta FromSeconds(int64_t seconds); 54 static TimeDelta FromSeconds(int64_t seconds);
54 static TimeDelta FromMilliseconds(int64_t milliseconds); 55 static TimeDelta FromMilliseconds(int64_t milliseconds);
55 static TimeDelta FromMicroseconds(int64_t microseconds) { 56 static TimeDelta FromMicroseconds(int64_t microseconds) {
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 271
271 } // namespace time_internal 272 } // namespace time_internal
272 273
273 274
274 // ----------------------------------------------------------------------------- 275 // -----------------------------------------------------------------------------
275 // Time 276 // Time
276 // 277 //
277 // This class represents an absolute point in time, internally represented as 278 // This class represents an absolute point in time, internally represented as
278 // microseconds (s/1,000,000) since 00:00:00 UTC, January 1, 1970. 279 // microseconds (s/1,000,000) since 00:00:00 UTC, January 1, 1970.
279 280
280 class Time final : public time_internal::TimeBase<Time> { 281 class V8_BASE_EXPORT Time final : public time_internal::TimeBase<Time> {
281 public: 282 public:
282 // Contains the NULL time. Use Time::Now() to get the current time. 283 // Contains the NULL time. Use Time::Now() to get the current time.
283 Time() : TimeBase(0) {} 284 Time() : TimeBase(0) {}
284 285
285 // Returns the current time. Watch out, the system might adjust its clock 286 // Returns the current time. Watch out, the system might adjust its clock
286 // in which case time will actually go backwards. We don't guarantee that 287 // in which case time will actually go backwards. We don't guarantee that
287 // times are increasing, or that two calls to Now() won't be the same. 288 // times are increasing, or that two calls to Now() won't be the same.
288 static Time Now(); 289 static Time Now();
289 290
290 // Returns the current time. Same as Now() except that this function always 291 // Returns the current time. Same as Now() except that this function always
(...skipping 24 matching lines...) Expand all
315 // Converts to/from the Javascript convention for times, a number of 316 // Converts to/from the Javascript convention for times, a number of
316 // milliseconds since the epoch: 317 // milliseconds since the epoch:
317 static Time FromJsTime(double ms_since_epoch); 318 static Time FromJsTime(double ms_since_epoch);
318 double ToJsTime() const; 319 double ToJsTime() const;
319 320
320 private: 321 private:
321 friend class time_internal::TimeBase<Time>; 322 friend class time_internal::TimeBase<Time>;
322 explicit Time(int64_t us) : TimeBase(us) {} 323 explicit Time(int64_t us) : TimeBase(us) {}
323 }; 324 };
324 325
325 std::ostream& operator<<(std::ostream&, const Time&); 326 V8_BASE_EXPORT std::ostream& operator<<(std::ostream&, const Time&);
326 327
327 inline Time operator+(const TimeDelta& delta, const Time& time) { 328 inline Time operator+(const TimeDelta& delta, const Time& time) {
328 return time + delta; 329 return time + delta;
329 } 330 }
330 331
331 332
332 // ----------------------------------------------------------------------------- 333 // -----------------------------------------------------------------------------
333 // TimeTicks 334 // TimeTicks
334 // 335 //
335 // This class represents an abstract time that is most of the time incrementing 336 // This class represents an abstract time that is most of the time incrementing
336 // for use in measuring time durations. It is internally represented in 337 // for use in measuring time durations. It is internally represented in
337 // microseconds. It can not be converted to a human-readable time, but is 338 // microseconds. It can not be converted to a human-readable time, but is
338 // guaranteed not to decrease (if the user changes the computer clock, 339 // guaranteed not to decrease (if the user changes the computer clock,
339 // Time::Now() may actually decrease or jump). But note that TimeTicks may 340 // Time::Now() may actually decrease or jump). But note that TimeTicks may
340 // "stand still", for example if the computer suspended. 341 // "stand still", for example if the computer suspended.
341 342
342 class TimeTicks final : public time_internal::TimeBase<TimeTicks> { 343 class V8_BASE_EXPORT TimeTicks final
344 : public time_internal::TimeBase<TimeTicks> {
343 public: 345 public:
344 TimeTicks() : TimeBase(0) {} 346 TimeTicks() : TimeBase(0) {}
345 347
346 // Platform-dependent tick count representing "right now." 348 // Platform-dependent tick count representing "right now."
347 // The resolution of this clock is ~1-15ms. Resolution varies depending 349 // The resolution of this clock is ~1-15ms. Resolution varies depending
348 // on hardware/operating system configuration. 350 // on hardware/operating system configuration.
349 // This method never returns a null TimeTicks. 351 // This method never returns a null TimeTicks.
350 static TimeTicks Now(); 352 static TimeTicks Now();
351 353
352 // Returns a platform-dependent high-resolution tick count. Implementation 354 // Returns a platform-dependent high-resolution tick count. Implementation
(...skipping 16 matching lines...) Expand all
369 371
370 inline TimeTicks operator+(const TimeDelta& delta, const TimeTicks& ticks) { 372 inline TimeTicks operator+(const TimeDelta& delta, const TimeTicks& ticks) {
371 return ticks + delta; 373 return ticks + delta;
372 } 374 }
373 375
374 376
375 // ThreadTicks ---------------------------------------------------------------- 377 // ThreadTicks ----------------------------------------------------------------
376 378
377 // Represents a clock, specific to a particular thread, than runs only while the 379 // Represents a clock, specific to a particular thread, than runs only while the
378 // thread is running. 380 // thread is running.
379 class ThreadTicks final : public time_internal::TimeBase<ThreadTicks> { 381 class V8_BASE_EXPORT ThreadTicks final
382 : public time_internal::TimeBase<ThreadTicks> {
380 public: 383 public:
381 ThreadTicks() : TimeBase(0) {} 384 ThreadTicks() : TimeBase(0) {}
382 385
383 // Returns true if ThreadTicks::Now() is supported on this system. 386 // Returns true if ThreadTicks::Now() is supported on this system.
384 static bool IsSupported(); 387 static bool IsSupported();
385 388
386 // Waits until the initialization is completed. Needs to be guarded with a 389 // Waits until the initialization is completed. Needs to be guarded with a
387 // call to IsSupported(). 390 // call to IsSupported().
388 static void WaitUntilInitialized() { 391 static void WaitUntilInitialized() {
389 #if V8_OS_WIN 392 #if V8_OS_WIN
(...skipping 11 matching lines...) Expand all
401 static ThreadTicks Now(); 404 static ThreadTicks Now();
402 405
403 #if V8_OS_WIN 406 #if V8_OS_WIN
404 // Similar to Now() above except this returns thread-specific CPU time for an 407 // Similar to Now() above except this returns thread-specific CPU time for an
405 // arbitrary thread. All comments for Now() method above apply apply to this 408 // arbitrary thread. All comments for Now() method above apply apply to this
406 // method as well. 409 // method as well.
407 static ThreadTicks GetForThread(const HANDLE& thread_handle); 410 static ThreadTicks GetForThread(const HANDLE& thread_handle);
408 #endif 411 #endif
409 412
410 private: 413 private:
414 template <class TimeClass>
415 friend class time_internal::TimeBase;
416
411 // Please use Now() or GetForThread() to create a new object. This is for 417 // Please use Now() or GetForThread() to create a new object. This is for
412 // internal use and testing. Ticks are in microseconds. 418 // internal use and testing. Ticks are in microseconds.
413 explicit ThreadTicks(int64_t ticks) : TimeBase(ticks) {} 419 explicit ThreadTicks(int64_t ticks) : TimeBase(ticks) {}
414 420
415 #if V8_OS_WIN 421 #if V8_OS_WIN
416 // Returns the frequency of the TSC in ticks per second, or 0 if it hasn't 422 // Returns the frequency of the TSC in ticks per second, or 0 if it hasn't
417 // been measured yet. Needs to be guarded with a call to IsSupported(). 423 // been measured yet. Needs to be guarded with a call to IsSupported().
418 static double TSCTicksPerSecond(); 424 static double TSCTicksPerSecond();
419 static bool IsSupportedWin(); 425 static bool IsSupportedWin();
420 static void WaitUntilInitializedWin(); 426 static void WaitUntilInitializedWin();
421 #endif 427 #endif
422 }; 428 };
423 429
424 } // namespace base 430 } // namespace base
425 } // namespace v8 431 } // namespace v8
426 432
427 #endif // V8_BASE_PLATFORM_TIME_H_ 433 #endif // V8_BASE_PLATFORM_TIME_H_
OLDNEW
« no previous file with comments | « src/base/platform/semaphore.h ('k') | src/base/sys-info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698