Fixing synchronization issues in TcpConnection and CircularQueue

mSocket in EtchTcpConnection and mItems in CircularQueue can be accessed
and modified from different threads. Till now these members have not been
protected during shutdown (close() and destructor).

Change-Id: Iaec4a6a43c84c87ad897dea2be355d35903a98ec

git-svn-id: https://svn.apache.org/repos/asf/etch/trunk@1580795 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp b/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp
index b7e0c6b..eade884 100644
--- a/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp
+++ b/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp
@@ -45,10 +45,12 @@
     delete mThread;
   }
 
+  mMutexConnection.lock();
   if (mSocket != NULL) {
     delete mSocket;
     mSocket = NULL;
   }
+  mMutexConnection.unlock();
 }
 
 status_t EtchTcpConnection::send(capu::int8_t* buf, capu::uint32_t off, capu::uint32_t len) {
@@ -255,12 +257,17 @@
 }
 
 status_t EtchTcpConnection::close() {
+  mMutexConnection.lock();
+  status_t result = ETCH_OK;
   if (mSocket != NULL) {
     ETCH_LOG_DEBUG(mRuntime->getLogger(), mRuntime->getLogger().getTransportContext(), mHost.c_str() << ":" << mPort << " => Socket has been closed");
-    return mSocket->close();
+    result = mSocket->close();
   } else {
-    return ETCH_ERROR;
+    result = ETCH_ERROR;
   }
+  mMutexConnection.unlock();
+
+  return result;
 }
 
 capu::bool_t EtchTcpConnection::isStarted() {
diff --git a/binding-cpp/runtime/src/main/util/EtchCircularQueue.cpp b/binding-cpp/runtime/src/main/util/EtchCircularQueue.cpp
index 3c1c90a..8902a69 100644
--- a/binding-cpp/runtime/src/main/util/EtchCircularQueue.cpp
+++ b/binding-cpp/runtime/src/main/util/EtchCircularQueue.cpp
@@ -33,7 +33,9 @@
 }
 
 EtchCircularQueue::~EtchCircularQueue() {
+  mMutex.lock();
   delete[] mItems;
+  mMutex.unlock();
 }
 
 capu::uint32_t EtchCircularQueue::getSize() {