diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-08-26 07:22:19 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2019-08-26 07:22:19 +0000 |
commit | 342e8e9753386b3e3e3d9a823723df63b8971308 (patch) | |
tree | 27969ec412e91fce6d2d27bdf09522c35bc624cf /config | |
parent | 78133f8c95b11b460aa4fd9ad89bd00bb716c6f8 (diff) |
Avoid calling time(nullptr)
Diffstat (limited to 'config')
-rw-r--r-- | config/src/vespa/config/frt/frtconnection.cpp | 15 | ||||
-rw-r--r-- | config/src/vespa/config/frt/frtconnection.h | 4 | ||||
-rw-r--r-- | config/src/vespa/config/frt/frtconnectionpool.cpp | 8 |
3 files changed, 16 insertions, 11 deletions
diff --git a/config/src/vespa/config/frt/frtconnection.cpp b/config/src/vespa/config/frt/frtconnection.cpp index bcdec9a4537..c5301a206aa 100644 --- a/config/src/vespa/config/frt/frtconnection.cpp +++ b/config/src/vespa/config/frt/frtconnection.cpp @@ -27,16 +27,16 @@ FRTConnection::FRTConnection(const vespalib::string& address, FRT_Supervisor& su FRTConnection::~FRTConnection() { - if (_target != NULL) { + if (_target != nullptr) { _target->SubRef(); - _target = NULL; + _target = nullptr; } } FRT_Target * FRTConnection::getTarget() { - if (_target == NULL) { + if (_target == nullptr) { _target = _supervisor.GetTarget(_address.c_str()); } else if ( ! _target->IsValid()) { _target->SubRef(); @@ -102,8 +102,7 @@ void FRTConnection::calculateSuspension(ErrorType type) } break; } - int64_t now = time(0); - now *= 1000; + int64_t now = milliSecsSinceEpoch(); _suspendedUntil = now + delay; if (_suspendWarned < (now - 5000)) { char date[32]; @@ -121,4 +120,10 @@ FRTConnection::allocRPCRequest() { return _supervisor.AllocRPCRequest(); } +using namespace std::chrono; +int64_t +FRTConnection::milliSecsSinceEpoch() { + return duration_cast<microseconds>(system_clock::now().time_since_epoch()).count(); +} + } diff --git a/config/src/vespa/config/frt/frtconnection.h b/config/src/vespa/config/frt/frtconnection.h index df57cfae92f..bde3e79b83c 100644 --- a/config/src/vespa/config/frt/frtconnection.h +++ b/config/src/vespa/config/frt/frtconnection.h @@ -34,7 +34,7 @@ public: enum ErrorType { TRANSIENT, FATAL }; FRTConnection(const vespalib::string & address, FRT_Supervisor & supervisor, const TimingValues & timingValues); - ~FRTConnection(); + ~FRTConnection() override; FRT_RPCRequest * allocRPCRequest() override; void invoke(FRT_RPCRequest * req, double timeout, FRT_IRequestWait * waiter) override; @@ -48,7 +48,7 @@ public: void setTransientDelay(int64_t delay) override { _transientDelay = delay; } int64_t getFatalDelay() { return _fatalDelay; } int64_t getMaxFatalDelay() { return getFatalDelay() * 6; } - void setFatalDelay(int64_t delay) { _fatalDelay = delay; } + static int64_t milliSecsSinceEpoch(); }; } // namespace config diff --git a/config/src/vespa/config/frt/frtconnectionpool.cpp b/config/src/vespa/config/frt/frtconnectionpool.cpp index b7440ceb7f0..5dccf033ab7 100644 --- a/config/src/vespa/config/frt/frtconnectionpool.cpp +++ b/config/src/vespa/config/frt/frtconnectionpool.cpp @@ -102,14 +102,15 @@ FRTConnectionPool::getNextHashBased() return nextFRTConnection; } + + const std::vector<FRTConnection *> & FRTConnectionPool::getReadySources(std::vector<FRTConnection*> & readySources) const { readySources.clear(); for (const auto & entry : _connections) { FRTConnection* source = entry.second.get(); - int64_t tnow = time(0); - tnow *= 1000; + int64_t tnow = FRTConnection::milliSecsSinceEpoch(); int64_t timestamp = tnow; if (source->getSuspendedUntil() < timestamp) { readySources.push_back(source); @@ -124,8 +125,7 @@ FRTConnectionPool::getSuspendedSources(std::vector<FRTConnection*> & suspendedSo suspendedSources.clear(); for (const auto & entry : _connections) { FRTConnection* source = entry.second.get(); - int64_t tnow = time(0); - tnow *= 1000; + int64_t tnow = FRTConnection::milliSecsSinceEpoch(); int64_t timestamp = tnow; if (source->getSuspendedUntil() >= timestamp) { suspendedSources.push_back(source); |