summaryrefslogtreecommitdiffstats
path: root/fnet
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2017-08-11 12:29:46 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2017-08-11 12:30:24 +0200
commit41709673f0165f16496ecf37162ed7dac06b5295 (patch)
treec213da683873bbe88927a3de58eb93f3f231a693 /fnet
parent2fe073e8e1875bc891c38099c880d156bd228e9d (diff)
Use std::atomic all over and completely get rid of homegrown atomics.
Diffstat (limited to 'fnet')
-rw-r--r--fnet/src/vespa/fnet/frt/rpcrequest.cpp4
-rw-r--r--fnet/src/vespa/fnet/frt/rpcrequest.h30
-rw-r--r--fnet/src/vespa/fnet/frt/target.h11
3 files changed, 21 insertions, 24 deletions
diff --git a/fnet/src/vespa/fnet/frt/rpcrequest.cpp b/fnet/src/vespa/fnet/frt/rpcrequest.cpp
index 6243f405639..9553a967413 100644
--- a/fnet/src/vespa/fnet/frt/rpcrequest.cpp
+++ b/fnet/src/vespa/fnet/frt/rpcrequest.cpp
@@ -129,7 +129,7 @@ void
FRT_RPCRequest::SubRef()
{
assert(_refcnt > 0);
- if (vespalib::Atomic::postDec(&_refcnt) == 1) {
+ if (_refcnt.fetch_sub(1) == 1) {
Reset();
delete this;
}
@@ -162,7 +162,7 @@ FRT_RPCRequest::CreateRequestPacket(bool wantReply)
flags |= FLAG_FRT_RPC_LITTLE_ENDIAN;
if (wantReply)
- AddRef_NoLock();
+ AddRef();
else
flags |= FLAG_FRT_RPC_NOREPLY;
diff --git a/fnet/src/vespa/fnet/frt/rpcrequest.h b/fnet/src/vespa/fnet/frt/rpcrequest.h
index 1b636bd9607..a10653ce2f6 100644
--- a/fnet/src/vespa/fnet/frt/rpcrequest.h
+++ b/fnet/src/vespa/fnet/frt/rpcrequest.h
@@ -5,8 +5,7 @@
#include "values.h"
#include "error.h"
#include <vespa/fnet/context.h>
-
-#include <vespa/vespalib/util/atomic.h>
+#include <atomic>
class FNETConnection;
class FNET_Packet;
@@ -55,17 +54,17 @@ class FRT_RPCRequest
{
private:
using Stash = vespalib::Stash;
- Stash _stash;
- FNET_Context _context;
- FRT_Values _params;
- FRT_Values _return;
- int _refcnt;
- int _completed;
- uint32_t _errorCode;
- uint32_t _errorMessageLen;
- uint32_t _methodNameLen;
- char *_errorMessage;
- char *_methodName;
+ Stash _stash;
+ FNET_Context _context;
+ FRT_Values _params;
+ FRT_Values _return;
+ std::atomic<int> _refcnt;
+ std::atomic<int> _completed;
+ uint32_t _errorCode;
+ uint32_t _errorMessageLen;
+ uint32_t _methodNameLen;
+ char *_errorMessage;
+ char *_methodName;
bool *_detachedPT;
FRT_IAbortHandler *_abortHandler;
@@ -87,8 +86,7 @@ public:
_return.DiscardBlobs();
}
- void AddRef_NoLock() { _refcnt++; } // be very carefull
- void AddRef() { vespalib::Atomic::postInc(&_refcnt); }
+ void AddRef() { _refcnt.fetch_add(1); }
void SubRef();
void SetContext(FNET_Context context) { _context = context; }
@@ -110,7 +108,7 @@ public:
return (spec != nullptr) ? spec : "";
}
- bool GetCompletionToken() { return (vespalib::Atomic::postInc(&_completed) == 0); }
+ bool GetCompletionToken() { return (_completed.fetch_add(1) == 0); }
void SetError(uint32_t errorCode, const char *errorMessage, uint32_t errorMessageLen);
void SetError(uint32_t errorCode, const char *errorMessage);
diff --git a/fnet/src/vespa/fnet/frt/target.h b/fnet/src/vespa/fnet/frt/target.h
index d8a2eaafa76..00834417122 100644
--- a/fnet/src/vespa/fnet/frt/target.h
+++ b/fnet/src/vespa/fnet/frt/target.h
@@ -2,8 +2,8 @@
#pragma once
-#include <vespa/vespalib/util/atomic.h>
#include <vespa/fnet/connection.h>
+#include <atomic>
class FNET_Scheduler;
class FRT_RPCRequest;
@@ -12,7 +12,7 @@ class FRT_IRequestWait;
class FRT_Target
{
private:
- int _refcnt;
+ std::atomic<int> _refcnt;
FNET_Scheduler *_scheduler;
FNET_Connection *_conn;
@@ -29,17 +29,16 @@ public:
FNET_Connection *GetConnection() const { return _conn; }
- void AddRef() { vespalib::Atomic::postInc(&_refcnt); }
+ void AddRef() { _refcnt++; }
void SubRef() {
- if (vespalib::Atomic::postDec(&_refcnt) == 1) {
+ if (_refcnt.fetch_sub(1) == 1) {
delete this;
}
}
int GetRefCnt() const { return _refcnt; }
- bool IsValid()
- {
+ bool IsValid() {
return ((_conn != nullptr) &&
(_conn->GetState() <= FNET_Connection::FNET_CONNECTED));
}