From 3d103e751433e9a6d686c7b97bde33db6e2bd30d Mon Sep 17 00:00:00 2001 From: Kenneth Anthony Giusti Date: Fri, 30 Mar 2012 16:25:21 +0000 Subject: QPID-3920: merge fix from trunk. git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/0.16@1307508 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/src/qpid/framing/FieldTable.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/qpid/cpp/src/qpid/framing/FieldTable.cpp b/qpid/cpp/src/qpid/framing/FieldTable.cpp index f9dc42916d..6534bec7bc 100644 --- a/qpid/cpp/src/qpid/framing/FieldTable.cpp +++ b/qpid/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 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 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 l(lock); cachedSize = buffer.getPosition() - p; cachedBytes = boost::shared_array(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 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 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. -- cgit v1.2.1