diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-01-13 02:17:25 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2017-01-13 02:17:25 +0100 |
commit | 527a73d8ddcf0c9c04dcb201d2df3eec60386708 (patch) | |
tree | e70065fd86013f581691542c5257f5b93efc64fb /fnet | |
parent | ccdefbbf566b3c72d2ebebcc758920094bef73b1 (diff) |
Need to discard the BlobRef
Diffstat (limited to 'fnet')
-rw-r--r-- | fnet/src/vespa/fnet/frt/values.cpp | 49 | ||||
-rw-r--r-- | fnet/src/vespa/fnet/frt/values.h | 38 |
2 files changed, 50 insertions, 37 deletions
diff --git a/fnet/src/vespa/fnet/frt/values.cpp b/fnet/src/vespa/fnet/frt/values.cpp index 7d5bc68fc09..1906fe03c6a 100644 --- a/fnet/src/vespa/fnet/frt/values.cpp +++ b/fnet/src/vespa/fnet/frt/values.cpp @@ -24,8 +24,54 @@ char * copyData(char *dst, const void *src, size_t len) { return dst; } +using vespalib::alloc::Alloc; +class LocalBlob : public FRT_ISharedBlob +{ +public: + LocalBlob(Alloc data, uint32_t len) : + _data(std::move(data)), + _len(len) + { } + LocalBlob(const char *data, uint32_t len); + void addRef() override {} + void subRef() override { Alloc().swap(_data); } + uint32_t getLen() override { return _len; } + const char *getData() override { return static_cast<const char *>(_data.get()); } + char *getInternalData() { return static_cast<char *>(_data.get()); } +private: + LocalBlob(const LocalBlob &); + LocalBlob &operator=(const LocalBlob &); + + Alloc _data; + uint32_t _len; +}; + +struct BlobRef +{ + FRT_DataValue *_value; // for blob inside data array + uint32_t _idx; // for blob as single data value + FRT_ISharedBlob *_blob; // interface to shared data + BlobRef *_next; // next in list + + BlobRef(FRT_DataValue *value, uint32_t idx, FRT_ISharedBlob *blob, BlobRef *next) + : _value(value), _idx(idx), _blob(blob), _next(next) { blob->addRef(); } + ~BlobRef() { discard(); } + void discard() { + if (_blob != nullptr) { + _blob->subRef(); + _blob = nullptr; + } + } +private: + BlobRef(const BlobRef &); + BlobRef &operator=(const BlobRef &); +}; + } +using fnet::BlobRef; +using fnet::LocalBlob; + FRT_Values::FRT_Values(Stash *tub) : _maxValues(0), _numValues(0), @@ -37,7 +83,7 @@ FRT_Values::FRT_Values(Stash *tub) FRT_Values::~FRT_Values() { } -FRT_Values::LocalBlob::LocalBlob(const char *data, uint32_t len) : +LocalBlob::LocalBlob(const char *data, uint32_t len) : _data(Alloc::alloc(len)), _len(len) { @@ -64,6 +110,7 @@ FRT_Values::DiscardBlobs() value->_buf = NULL; value->_len = 0; } + ref->~BlobRef(); } } diff --git a/fnet/src/vespa/fnet/frt/values.h b/fnet/src/vespa/fnet/frt/values.h index a5d0e730884..ff1ec3fa11d 100644 --- a/fnet/src/vespa/fnet/frt/values.h +++ b/fnet/src/vespa/fnet/frt/values.h @@ -9,6 +9,7 @@ namespace fnet { char * copyString(char *dst, const char *src, size_t len); char * copyData(char *dst, const void *src, size_t len); + class BlobRef; } class FNET_DataBuffer; @@ -81,48 +82,13 @@ class FRT_Values public: using Stash = vespalib::Stash; using Alloc = vespalib::alloc::Alloc; - class LocalBlob : public FRT_ISharedBlob - { - public: - LocalBlob(Alloc data, uint32_t len) : - _data(std::move(data)), - _len(len) - { } - LocalBlob(const char *data, uint32_t len); - void addRef() override {} - void subRef() override { Alloc().swap(_data); } - uint32_t getLen() override { return _len; } - const char *getData() override { return static_cast<const char *>(_data.get()); } - char *getInternalData() { return static_cast<char *>(_data.get()); } - private: - LocalBlob(const LocalBlob &); - LocalBlob &operator=(const LocalBlob &); - - Alloc _data; - uint32_t _len; - }; - - struct BlobRef - { - FRT_DataValue *_value; // for blob inside data array - uint32_t _idx; // for blob as single data value - FRT_ISharedBlob *_blob; // interface to shared data - BlobRef *_next; // next in list - - BlobRef(FRT_DataValue *value, uint32_t idx, FRT_ISharedBlob *blob, BlobRef *next) - : _value(value), _idx(idx), _blob(blob), _next(next) { blob->addRef(); } - ~BlobRef() { _blob->subRef(); } - private: - BlobRef(const BlobRef &); - BlobRef &operator=(const BlobRef &); - }; private: uint32_t _maxValues; uint32_t _numValues; char *_typeString; FRT_Value *_values; - BlobRef *_blobs; + fnet::BlobRef *_blobs; Stash *_tub; public: |