summaryrefslogtreecommitdiffstats
path: root/storageapi
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2017-06-07 08:58:13 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2017-06-07 09:50:24 +0200
commit91be30ced7a740dad61e1df80b5eea4e27d26fe7 (patch)
treec2ed68d1c7db718de7757cb926fc4c88c1b7f1fe /storageapi
parent834265f2357c41a60668780fa8ce15daf041f818 (diff)
Hide the lock
Diffstat (limited to 'storageapi')
-rw-r--r--storageapi/src/vespa/storageapi/messageapi/storagemessage.cpp40
-rw-r--r--storageapi/src/vespa/storageapi/messageapi/storagemessage.h34
2 files changed, 38 insertions, 36 deletions
diff --git a/storageapi/src/vespa/storageapi/messageapi/storagemessage.cpp b/storageapi/src/vespa/storageapi/messageapi/storagemessage.cpp
index 536135c48e6..16f4d10c448 100644
--- a/storageapi/src/vespa/storageapi/messageapi/storagemessage.cpp
+++ b/storageapi/src/vespa/storageapi/messageapi/storagemessage.cpp
@@ -2,13 +2,20 @@
#include "storagemessage.h"
-#include <vespa/vespalib/util/exceptions.h>
#include <vespa/messagebus/routing/verbatimdirective.h>
+#include <vespa/vespalib/util/exceptions.h>
+#include <vespa/vespalib/util/sync.h>
#include <vespa/vespalib/stllike/asciistream.h>
#include <sstream>
+#include <cassert>
+
+namespace storage::api {
+
+namespace {
-namespace storage {
-namespace api {
+vespalib::Lock _G_msgIdLock;
+
+}
static const vespalib::string STORAGEADDRESS_PREFIX = "storage/cluster.";
@@ -177,6 +184,20 @@ MessageType::MessageType::get(Id id)
}
return *it->second;
}
+MessageType::MessageType(const vespalib::stringref & name, Id id,
+ const MessageType* replyOf = 0)
+ : _name(name), _id(id), _reply(NULL), _replyOf(replyOf)
+{
+ _codes[id] = this;
+ if (_replyOf != 0) {
+ assert(_replyOf->_reply == 0);
+ // Ugly cast to let initialization work
+ MessageType& type = const_cast<MessageType&>(*_replyOf);
+ type._reply = this;
+ }
+}
+
+MessageType::~MessageType() {}
void
MessageType::print(std::ostream& out, bool verbose, const std::string& indent) const
@@ -305,17 +326,14 @@ StorageMessageAddress::print(vespalib::asciistream & out) const
}
}
-TransportContext::~TransportContext()
-{
-}
+TransportContext::~TransportContext() { }
-vespalib::Lock StorageMessage::_msgIdLock;
StorageMessage::Id StorageMessage::_lastMsgId = 1000;
StorageMessage::Id
StorageMessage::generateMsgId()
{
- vespalib::LockGuard sync(_msgIdLock);
+ vespalib::LockGuard sync(_G_msgIdLock);
Id msgId = _lastMsgId++;
_lastMsgId &= ((Id(-1) << 8) >> 8);
return msgId;
@@ -343,7 +361,7 @@ StorageMessage::~StorageMessage() { }
void StorageMessage::setNewMsgId()
{
- vespalib::LockGuard sync(_msgIdLock);
+ vespalib::LockGuard sync(_G_msgIdLock);
_msgId = _lastMsgId++;
_lastMsgId &= ((Id(-1) << 8) >> 8);
}
@@ -353,5 +371,5 @@ StorageMessage::getSummary() const {
return toString();
}
-} // api
-} // storage
+}
+
diff --git a/storageapi/src/vespa/storageapi/messageapi/storagemessage.h b/storageapi/src/vespa/storageapi/messageapi/storagemessage.h
index 59ae462432b..442ee0c9899 100644
--- a/storageapi/src/vespa/storageapi/messageapi/storagemessage.h
+++ b/storageapi/src/vespa/storageapi/messageapi/storagemessage.h
@@ -19,7 +19,6 @@
#include <vespa/vdslib/state/nodetype.h>
#include <vespa/document/bucket/bucketid.h>
#include <vespa/vespalib/util/printable.h>
-#include <vespa/vespalib/util/sync.h>
#include <map>
namespace vespalib {
@@ -82,10 +81,6 @@ namespace api {
* This is used to be able to deserialize messages of various classes.
*/
class MessageType : public vespalib::Printable {
-private:
- MessageType(const MessageType &);
- MessageType& operator=(const MessageType &);
-
public:
enum Id {
GET_ID = 4,
@@ -172,18 +167,7 @@ private:
MessageType *_reply;
const MessageType *_replyOf;
- MessageType(const vespalib::stringref & name, Id id,
- const MessageType* replyOf = 0)
- : _name(name), _id(id), _reply(NULL), _replyOf(replyOf)
- {
- _codes[id] = this;
- if (_replyOf != 0) {
- assert(_replyOf->_reply == 0);
- // Ugly cast to let initialization work
- MessageType& type = const_cast<MessageType&>(*_replyOf);
- type._reply = this;
- }
- }
+ MessageType(const vespalib::stringref & name, Id id, const MessageType* replyOf = 0);
public:
static const MessageType DOCBLOCK;
static const MessageType DOCBLOCK_REPLY;
@@ -264,16 +248,17 @@ public:
static const MessageType& get(Id id);
+ MessageType(const MessageType &) = delete;
+ MessageType& operator=(const MessageType &) = delete;
+ ~MessageType();
Id getId() const { return _id; }
static Id getMaxId() { return MESSAGETYPE_MAX_ID; }
const vespalib::string& getName() const { return _name; }
bool isReply() const { return (_replyOf != 0); }
- /** Only valid to call on replies. */
- const MessageType& getCommandType() const
- { assert(_replyOf); return *_replyOf; }
- /** Only valid to call on commands. */
- const MessageType& getReplyType() const
- { assert(_reply); return *_reply; }
+ /** Only valid to call on replies. */
+ const MessageType& getCommandType() const { return *_replyOf; }
+ /** Only valid to call on commands. */
+ const MessageType& getReplyType() const { return *_reply; }
bool operator==(const MessageType& type) const { return (_id == type._id); }
bool operator!=(const MessageType& type) const { return (_id != type._id); }
@@ -294,7 +279,7 @@ private:
mbus::Route _route;
bool _retryEnabled;
Protocol _protocol;
- // Used for internal VDS addresses only
+ // Used for internal VDS addresses only
vespalib::string _cluster;
const lib::NodeType* _type;
uint16_t _index;
@@ -346,7 +331,6 @@ public:
static const char* getPriorityString(Priority);
private:
- static vespalib::Lock _msgIdLock;
static Id _lastMsgId;
StorageMessage& operator=(const StorageMessage&);