diff options
author | Kenneth Anthony Giusti <kgiusti@apache.org> | 2012-03-28 15:37:41 +0000 |
---|---|---|
committer | Kenneth Anthony Giusti <kgiusti@apache.org> | 2012-03-28 15:37:41 +0000 |
commit | 41d68d7d87aaa8f376461bcea3b99edd21e0b283 (patch) | |
tree | ee7ee6bfa7e0f22f76f4bebf36d42fb8fd796310 /cpp/src | |
parent | 378b6e8d57b30cb8e4c2a9128a6feaec6181e8ec (diff) | |
download | qpid-python-41d68d7d87aaa8f376461bcea3b99edd21e0b283.tar.gz |
QPID-3920: keep cache data and length atomic with respect to each other.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1306434 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/qpid/framing/FieldTable.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/cpp/src/qpid/framing/FieldTable.cpp b/cpp/src/qpid/framing/FieldTable.cpp index f9dc42916d..6534bec7bc 100644 --- a/cpp/src/qpid/framing/FieldTable.cpp +++ b/cpp/src/qpid/framing/FieldTable.cpp @@ -54,11 +54,14 @@ FieldTable::FieldTable() : { } -FieldTable::FieldTable(const FieldTable& ft) : - cachedBytes(ft.cachedBytes), - cachedSize(ft.cachedSize), - newBytes(ft.newBytes) +FieldTable::FieldTable(const FieldTable& ft) { + ScopedLock<Mutex> l(ft.lock); // lock _source_ FieldTable + + cachedBytes = ft.cachedBytes; + cachedSize = ft.cachedSize; + newBytes = ft.newBytes; + // Only copy the values if we have no raw data // - copying the map is expensive and we can // reconstruct it if necessary from the raw data @@ -251,6 +254,7 @@ bool FieldTable::getDouble(const std::string& name, double& value) const { //} void FieldTable::encode(Buffer& buffer) const { + ScopedLock<Mutex> l(lock); // If we've still got the input field table // we can just copy it directly to the output if (cachedBytes) { @@ -264,7 +268,6 @@ void FieldTable::encode(Buffer& buffer) const { i->second->encode(buffer); } // Now create raw bytes in case we are used again - ScopedLock<Mutex> l(lock); cachedSize = buffer.getPosition() - p; cachedBytes = boost::shared_array<uint8_t>(new uint8_t[cachedSize]); buffer.setPosition(p); @@ -283,6 +286,7 @@ void FieldTable::decode(Buffer& buffer){ if ((available < len) || (available < 4)) throw IllegalArgumentException(QPID_MSG("Not enough data for field table.")); } + ScopedLock<Mutex> l(lock); // Throw away previous stored values values.clear(); // Copy data into our buffer @@ -321,6 +325,7 @@ void FieldTable::realDecode() const void FieldTable::flushRawCache() { + ScopedLock<Mutex> l(lock); // We can only flush the cache if there are no cached bytes to decode assert(newBytes==false); // Avoid recreating shared array unless we actually have one. |