diff options
author | Tor Egge <Tor.Egge@oath.com> | 2017-10-27 14:44:36 +0000 |
---|---|---|
committer | Tor Egge <Tor.Egge@oath.com> | 2017-10-27 14:44:36 +0000 |
commit | 1ce9039e242310b5d04190e7758dbaf72edc294b (patch) | |
tree | ecb892aea9ac12778b5bc94b6956af8ed4c5bc31 /fnet | |
parent | f4e904b05e7c1fd9d4cda3ace693b41912ac6622 (diff) |
Eliminate unneeded temporaries and unneede scopes.
Diffstat (limited to 'fnet')
-rw-r--r-- | fnet/src/tests/frt/rpc/invoke.cpp | 3 | ||||
-rw-r--r-- | fnet/src/vespa/fnet/connection.cpp | 34 | ||||
-rw-r--r-- | fnet/src/vespa/fnet/connection.h | 1 | ||||
-rw-r--r-- | fnet/src/vespa/fnet/packetqueue.cpp | 3 |
4 files changed, 18 insertions, 23 deletions
diff --git a/fnet/src/tests/frt/rpc/invoke.cpp b/fnet/src/tests/frt/rpc/invoke.cpp index dfeb01f6542..f44a58dd8b3 100644 --- a/fnet/src/tests/frt/rpc/invoke.cpp +++ b/fnet/src/tests/frt/rpc/invoke.cpp @@ -45,8 +45,7 @@ struct LockedReqWait : public FRT_IRequestWait bool isLocked() { std::lock_guard<std::mutex> guard(_lockLock); - bool ret = _lock; - return ret; + return _lock; } void RequestDone(FRT_RPCRequest *) override { diff --git a/fnet/src/vespa/fnet/connection.cpp b/fnet/src/vespa/fnet/connection.cpp index 9fd3f52cc09..96a18dc9727 100644 --- a/fnet/src/vespa/fnet/connection.cpp +++ b/fnet/src/vespa/fnet/connection.cpp @@ -571,11 +571,9 @@ FNET_Connection::OpenChannel() bool FNET_Connection::CloseChannel(FNET_Channel *channel) { - bool ret; std::unique_lock<std::mutex> guard(_ioc_lock); WaitCallback(guard, channel); - ret = _channels.Unregister(channel); - return ret; + return _channels.Unregister(channel); } @@ -583,8 +581,7 @@ void FNET_Connection::FreeChannel(FNET_Channel *channel) { delete channel; - std::unique_lock<std::mutex> guard(_ioc_lock); - SubRef_HasLock(std::move(guard)); + SubRef_HasLock(std::unique_lock<std::mutex>(_ioc_lock)); } @@ -656,9 +653,7 @@ uint32_t FNET_Connection::GetQueueLen() { std::unique_lock<std::mutex> guard(_ioc_lock); - uint32_t ret = _queue.GetPacketCnt_NoLock() - + _myQueue.GetPacketCnt_NoLock(); - return ret; + return _queue.GetPacketCnt_NoLock() + _myQueue.GetPacketCnt_NoLock(); } @@ -713,6 +708,16 @@ FNET_Connection::HandleReadEvent() bool +FNET_Connection::enterConnectedState() +{ + std::unique_lock<std::mutex> guard(_ioc_lock); + _state = FNET_CONNECTED; // SetState(FNET_CONNECTED) + LOG(debug, "Connection(%s): State transition: %s -> %s", GetSpec(), + GetStateString(FNET_CONNECTING), GetStateString(FNET_CONNECTED)); + return (_writeWork > 0); +} + +bool FNET_Connection::HandleWriteEvent() { int error; // socket error code @@ -722,16 +727,9 @@ FNET_Connection::HandleWriteEvent() case FNET_CONNECTING: error = _socket.get_so_error(); if (error == 0) { // connect ok - bool writePending; - { - std::unique_lock<std::mutex> guard(_ioc_lock); - _state = FNET_CONNECTED; // SetState(FNET_CONNECTED) - LOG(debug, "Connection(%s): State transition: %s -> %s", GetSpec(), - GetStateString(FNET_CONNECTING), GetStateString(FNET_CONNECTED)); - writePending = (_writeWork > 0); - } - if (!writePending) + if (!enterConnectedState()) { EnableWriteEvent(false); + } } else { LOG(debug, "Connection(%s): connect error: %d", GetSpec(), error); @@ -740,7 +738,6 @@ FNET_Connection::HandleWriteEvent() } break; case FNET_CONNECTED: - { { std::unique_lock<std::mutex> guard(_ioc_lock); if (_flags._writeLock) { @@ -753,7 +750,6 @@ FNET_Connection::HandleWriteEvent() } broken = !Write(false); break; - } case FNET_CLOSING: case FNET_CLOSED: default: diff --git a/fnet/src/vespa/fnet/connection.h b/fnet/src/vespa/fnet/connection.h index 1126f8bf1e6..ffb160bb904 100644 --- a/fnet/src/vespa/fnet/connection.h +++ b/fnet/src/vespa/fnet/connection.h @@ -215,6 +215,7 @@ private: **/ bool Write(bool direct); + bool enterConnectedState(); public: /** diff --git a/fnet/src/vespa/fnet/packetqueue.cpp b/fnet/src/vespa/fnet/packetqueue.cpp index a4ab601368a..4fdb5842a9d 100644 --- a/fnet/src/vespa/fnet/packetqueue.cpp +++ b/fnet/src/vespa/fnet/packetqueue.cpp @@ -238,8 +238,7 @@ FNET_PacketQueue::DequeuePacket(uint32_t maxwait, FNET_Context *context) bool timeout = false; _waitCnt++; - while ((_bufused == 0) && !timeout - && (waitTime = (int)(maxwait - startTime.MilliSecsToNow())) > 0) { + while ((_bufused == 0) && !timeout && (waitTime = (int)(maxwait - startTime.MilliSecsToNow())) > 0) { timeout = _cond.wait_for(guard, std::chrono::milliseconds(waitTime)) == std::cv_status::timeout; } _waitCnt--; |