summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Anthony Giusti <kgiusti@apache.org>2012-03-30 16:25:21 +0000
committerKenneth Anthony Giusti <kgiusti@apache.org>2012-03-30 16:25:21 +0000
commit3d103e751433e9a6d686c7b97bde33db6e2bd30d (patch)
treee0270d2f47b212f04bc11c10934ef00d431e667f
parentc5eaee99ad719218c886440ac5705bde760ca3ae (diff)
downloadqpid-python-3d103e751433e9a6d686c7b97bde33db6e2bd30d.tar.gz
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
-rw-r--r--qpid/cpp/src/qpid/framing/FieldTable.cpp15
1 files 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<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.