You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by ve...@apache.org on 2014/03/24 10:51:02 UTC

svn commit: r1580795 - in /etch/trunk/binding-cpp/runtime/src/main: transport/EtchTcpConnection.cpp util/EtchCircularQueue.cpp

Author: veithm
Date: Mon Mar 24 09:51:02 2014
New Revision: 1580795

URL: http://svn.apache.org/r1580795
Log:
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

Modified:
    etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp
    etch/trunk/binding-cpp/runtime/src/main/util/EtchCircularQueue.cpp

Modified: etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp
URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp?rev=1580795&r1=1580794&r2=1580795&view=diff
==============================================================================
--- etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp (original)
+++ etch/trunk/binding-cpp/runtime/src/main/transport/EtchTcpConnection.cpp Mon Mar 24 09:51:02 2014
@@ -45,10 +45,12 @@ EtchTcpConnection::~EtchTcpConnection() 
     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 @@ void EtchTcpConnection::setSession(EtchS
 }
 
 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() {

Modified: etch/trunk/binding-cpp/runtime/src/main/util/EtchCircularQueue.cpp
URL: http://svn.apache.org/viewvc/etch/trunk/binding-cpp/runtime/src/main/util/EtchCircularQueue.cpp?rev=1580795&r1=1580794&r2=1580795&view=diff
==============================================================================
--- etch/trunk/binding-cpp/runtime/src/main/util/EtchCircularQueue.cpp (original)
+++ etch/trunk/binding-cpp/runtime/src/main/util/EtchCircularQueue.cpp Mon Mar 24 09:51:02 2014
@@ -33,7 +33,9 @@ EtchCircularQueue::EtchCircularQueue(cap
 }
 
 EtchCircularQueue::~EtchCircularQueue() {
+  mMutex.lock();
   delete[] mItems;
+  mMutex.unlock();
 }
 
 capu::uint32_t EtchCircularQueue::getSize() {