diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-11-20 10:12:23 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2019-11-20 21:55:01 +0000 |
commit | 490bdc5f1c510ca05ed709008fdd74226bba36d1 (patch) | |
tree | 67e4129e43a75fdce20bb841a4f7ff3d81253ff5 /fastos/src | |
parent | dae2799f522bf973d4baa99abd04bd3fbe3454a5 (diff) |
And that ends the life of FastOS_Time.
Diffstat (limited to 'fastos/src')
-rw-r--r-- | fastos/src/vespa/fastos/CMakeLists.txt | 2 | ||||
-rw-r--r-- | fastos/src/vespa/fastos/time.cpp | 19 | ||||
-rw-r--r-- | fastos/src/vespa/fastos/time.h | 132 | ||||
-rw-r--r-- | fastos/src/vespa/fastos/unix_time.cpp | 104 | ||||
-rw-r--r-- | fastos/src/vespa/fastos/unix_time.h | 98 |
5 files changed, 0 insertions, 355 deletions
diff --git a/fastos/src/vespa/fastos/CMakeLists.txt b/fastos/src/vespa/fastos/CMakeLists.txt index 48f1e587918..fb5e7b2901e 100644 --- a/fastos/src/vespa/fastos/CMakeLists.txt +++ b/fastos/src/vespa/fastos/CMakeLists.txt @@ -7,7 +7,6 @@ vespa_add_library(fastos_objects OBJECT linux_file.cpp process.cpp thread.cpp - time.cpp timestamp.cpp unix_app.cpp unix_dynamiclibrary.cpp @@ -15,7 +14,6 @@ vespa_add_library(fastos_objects OBJECT unix_ipc.cpp unix_process.cpp unix_thread.cpp - unix_time.cpp ) vespa_add_library(fastos diff --git a/fastos/src/vespa/fastos/time.cpp b/fastos/src/vespa/fastos/time.cpp deleted file mode 100644 index a5330e69def..00000000000 --- a/fastos/src/vespa/fastos/time.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include <vespa/fastos/time.h> - -double -FastOS_TimeInterface::MicroSecsToNow(void) const -{ - FastOS_Time now; - now.SetNow(); - return now.MicroSecs() - MicroSecs(); -} - -double -FastOS_TimeInterface::MilliSecsToNow(void) const -{ - FastOS_Time now; - now.SetNow(); - return now.MilliSecs() - MilliSecs(); -} diff --git a/fastos/src/vespa/fastos/time.h b/fastos/src/vespa/fastos/time.h deleted file mode 100644 index ef711f44683..00000000000 --- a/fastos/src/vespa/fastos/time.h +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#pragma once - -/** - * Interface to OS time functions. - */ -class FastOS_TimeInterface -{ -protected: - /** - * Destructor. No cleanup needed for base class. - */ - virtual ~FastOS_TimeInterface() { } - -public: - /** - * Set the time to 0. - */ - virtual void SetZero() = 0; - - /** - * Set the time, specified by number of seconds. - * @param seconds Number of seconds. - */ - FastOS_TimeInterface& operator=(const double seconds) - { - SetSecs(seconds); - return *this; - } - - /** - * Return the microsecond difference between the current time - * and the time stored in the instance. - * Note: Only millisecond accuracy is guaranteed. - * @return Time difference in microseconds. - */ - double MicroSecsToNow() const; - /** - * Return the millisecond difference between the current time - * and the time stored in the instance. - * @return Time difference in milliseconds. - */ - double MilliSecsToNow() const; - - /** - * Add a specified number of microseconds to the time. - * Note: Only millisecond accuracy is guaranteed. - * @param microsecs Number of microseconds to add. - */ - void AddMicroSecs(double microsecs) { SetMicroSecs(MicroSecs() + microsecs); } - - /** - * Add a specified number of milliseconds to the time. - * @param millisecs Number of milliseconds to add. - */ - void AddMilliSecs(double millisecs) { SetMilliSecs(MilliSecs() + millisecs); } - - /** - * Subtract a specified number of microseconds from the time. - * Note: Only millisecond accuracy is guaranteed. - * @param microsecs Number of microseconds to subtract. - */ - void SubtractMicroSecs(double microsecs) { SetMicroSecs(MicroSecs() - microsecs); } - - /** - * Subtract a specified number of milliseconds from the time. - * @param millisecs Number of milliseconds to subtract. - */ - void SubtractMilliSecs(double millisecs) { SetMilliSecs(MilliSecs() - millisecs); } - - /** - * Return the time in microseconds. - * Note: Only millisecond accuracy is guaranteed. - * @return Time in microseconds. - */ - virtual double MicroSecs() const = 0; - - /** - * Return the time in milliseconds. - * @return Time in milliseconds. - */ - virtual double MilliSecs() const = 0; - - /** - * Return the time in seconds. - * @return Time in seconds. - */ - virtual double Secs() const = 0; - - /** - * Set the time, specified in microseconds. - * Note: Only millisecond accuracy is guaranteed. - * @param microsecs Time in microseconds. - */ - virtual void SetMicroSecs(double microsecs) = 0; - - /** - * Set the time, specified in milliseconds. - * @param millisecs Time in milliseconds. - */ - virtual void SetMilliSecs(double millisecs) = 0; - - /** - * Set the time, specified in seconds. - * @param secs Time in seconds. - */ - virtual void SetSecs(double secs) = 0; - - /** - * Set the time value to the current system time. - */ - virtual void SetNow() = 0; - - /** - * Get the seconds-part of the time value. If the time value - * is 56.1234, this method will return 56. - * @return Number of seconds. - */ - virtual long int GetSeconds() const = 0; - - /** - * Get the microsecond-part of the time value. If the time - * value is 56.123456, this method will return 123456. - * Note: Only millisecond accuracy is guaranteed. - * @return Number of microseconds. - */ - virtual long int GetMicroSeconds() const = 0; -}; - -#include <vespa/fastos/unix_time.h> -using FastOS_Time = FastOS_UNIX_Time; - diff --git a/fastos/src/vespa/fastos/unix_time.cpp b/fastos/src/vespa/fastos/unix_time.cpp deleted file mode 100644 index c6251f60d03..00000000000 --- a/fastos/src/vespa/fastos/unix_time.cpp +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include "time.h" -#include <sys/time.h> - -double -FastOS_UNIX_Time::MicroSecs() const -{ - return ((1000.0 * 1000.0) * _time.tv_sec) + _time.tv_usec; -} - -double -FastOS_UNIX_Time::MilliSecs() const -{ - return 1000.0 * _time.tv_sec + static_cast<double>(_time.tv_usec) / 1000.0; -} - -double -FastOS_UNIX_Time::Secs() const -{ - return _time.tv_sec + static_cast<double>(_time.tv_usec) / 1000000.0; -} - -FastOS_UNIX_Time& -FastOS_UNIX_Time::operator=(const FastOS_UNIX_Time& rhs) -{ - _time.tv_sec = rhs._time.tv_sec; - _time.tv_usec = rhs._time.tv_usec; - return *this; -} - - -FastOS_UNIX_Time& -FastOS_UNIX_Time::operator+=(const FastOS_UNIX_Time &rhs) -{ - struct timeval result; - FASTOS_UNIX_TIMER_ADD(&_time, &rhs._time, &result); - _time = result; - return *this; -} - - -FastOS_UNIX_Time& -FastOS_UNIX_Time::operator-=(const FastOS_UNIX_Time &rhs) -{ - struct timeval result; - FASTOS_UNIX_TIMER_SUB(&_time, &rhs._time, &result); - _time = result; - return *this; -} - -void -FastOS_UNIX_Time::SetMicroSecs(double microsecs) -{ - if (microsecs > 0) { - _time.tv_sec = static_cast<int>(microsecs / (1000 * 1000)); - _time.tv_usec = static_cast<int>(microsecs - (1000.0 * 1000.0) * - _time.tv_sec); - } - else { - _time.tv_sec = - static_cast<int>(- microsecs / (1000 * 1000)); - _time.tv_usec = - static_cast<int>(- microsecs - - (1000.0 * 1000.0) * - (- _time.tv_sec)); - } -} - -void -FastOS_UNIX_Time::SetMilliSecs(double millisecs) -{ - if (millisecs > 0) { - _time.tv_sec = static_cast<int>(millisecs/1000); - _time.tv_usec = static_cast<int>((millisecs - 1000.0 * _time.tv_sec) * - 1000); - } - else { - // some of the "-" may be unnecessary . - // round on positive numbers to make sure conversion to int is ok. - _time.tv_sec = - static_cast<int>(- millisecs / 1000); - _time.tv_usec = - static_cast<int>((- millisecs - 1000.0 * - ( -_time.tv_sec)) * 1000); - } -} - - -void -FastOS_UNIX_Time::SetSecs(double secs) -{ - if (secs > 0) { - _time.tv_sec = static_cast<int>(secs); - _time.tv_usec = static_cast<int>((secs - _time.tv_sec) * 1000000); - } - else { - // some of the "-" may be unnecessary . - // round on positive numbers to make sure conversion to int is ok. - _time.tv_sec = - static_cast<int>(- secs); - _time.tv_usec = - static_cast<int>((- secs - (-_time.tv_sec)) * 1000000); - } -} - -void FastOS_UNIX_Time::SetNow() { - gettimeofday(&_time, nullptr); -} - diff --git a/fastos/src/vespa/fastos/unix_time.h b/fastos/src/vespa/fastos/unix_time.h deleted file mode 100644 index 82254c98f8d..00000000000 --- a/fastos/src/vespa/fastos/unix_time.h +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#pragma once - -#include <vespa/fastos/time.h> -#include <vespa/fastos/timestamp.h> - - -#define FASTOS_UNIX_TIMER_CMP(tvp, uvp, cmp) \ - (((tvp)->tv_sec == (uvp)->tv_sec)? \ - ((tvp)->tv_usec cmp (uvp)->tv_usec) :\ - ((tvp)->tv_sec cmp (uvp)->tv_sec)) - -#define FASTOS_UNIX_TIMER_SUB(tvp, uvp, vvp) \ - do { \ - if ((tvp)->tv_usec >= (uvp)->tv_usec) {\ - (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ - (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec;\ - } else {\ - (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec - 1; \ - (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec + 1000000;\ - }\ - } while (0) - -#define FASTOS_UNIX_TIMER_ADD(tvp, uvp, vvp) \ - do { \ - if ((tvp)->tv_usec+(uvp)->tv_usec<1000000) {\ - (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ - (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec;\ - } else {\ - (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec + 1; \ - (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec - 1000000;\ - }\ - } while (0) - - -class FastOS_UNIX_Time : public FastOS_TimeInterface -{ - /* - * Class for OS independent time to millisecond resolution. - * - */ -private: - timeval _time; - -public: - void SetZero() override { _time.tv_sec = 0; _time.tv_usec = 0; } - - FastOS_UNIX_Time () - : _time() - { - SetZero(); - } - - FastOS_UNIX_Time (double s) - : _time() - { - SetMilliSecs(s * 1000.0); - } - - FastOS_UNIX_Time(const FastOS_UNIX_Time &rhs) = default; - - operator fastos::TimeStamp () { - return fastos::TimeStamp(_time); - } - - FastOS_UNIX_Time& operator=(const FastOS_UNIX_Time& rhs); - FastOS_UNIX_Time& operator+=(const FastOS_UNIX_Time& rhs); - FastOS_UNIX_Time& operator-=(const FastOS_UNIX_Time& rhs); - - bool operator>(const FastOS_UNIX_Time rhs) const { - return FASTOS_UNIX_TIMER_CMP(&_time, &rhs._time, >); - } - bool operator<(const FastOS_UNIX_Time rhs) const { - return FASTOS_UNIX_TIMER_CMP(&_time, &rhs._time, <); - } - bool operator>=(const FastOS_UNIX_Time rhs) const { - return FASTOS_UNIX_TIMER_CMP(&_time, &rhs._time, >=); - } - bool operator<=(const FastOS_UNIX_Time rhs) const { - return FASTOS_UNIX_TIMER_CMP(&_time, &rhs._time, <=); - } - bool operator==(const FastOS_UNIX_Time rhs) const { - return FASTOS_UNIX_TIMER_CMP(&_time, &rhs._time, ==); - } - - double MicroSecs() const override; - double MilliSecs() const override; - double Secs() const override; - - void SetMicroSecs(double microsecs) override; - void SetMilliSecs(double millisecs) override; - void SetSecs(double secs) override; - - void SetNow() override; - - long int GetSeconds() const override { return _time.tv_sec; } - long int GetMicroSeconds() const override { return _time.tv_usec; } -}; |