Renaming mutexes in EtchPlainMailbox and EtchPlainMailboxManager

Till now the mutexes in both files were named simple mMutex.
Now the mutexes got more meaningful names which tell what they
do protect.

Change-Id: I769744e2342714d4536b5f89ef6bfcfdc13456ee

git-svn-id: https://svn.apache.org/repos/asf/etch/trunk@1578886 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/binding-cpp/runtime/include/support/EtchPlainMailbox.h b/binding-cpp/runtime/include/support/EtchPlainMailbox.h
index adb2154..f1bcc53 100644
--- a/binding-cpp/runtime/include/support/EtchPlainMailbox.h
+++ b/binding-cpp/runtime/include/support/EtchPlainMailbox.h
@@ -135,7 +135,7 @@
   EtchLong mMessageId;
   capu::bool_t mAlarmSet;
   EtchCircularQueue mQueue;
-  capu::Mutex mMutex;
+  capu::Mutex mQueueMutex;
 
   void fireNotify();
 };
diff --git a/binding-cpp/runtime/include/transport/EtchPlainMailboxManager.h b/binding-cpp/runtime/include/transport/EtchPlainMailboxManager.h
index 074a4a3..480a09d 100644
--- a/binding-cpp/runtime/include/transport/EtchPlainMailboxManager.h
+++ b/binding-cpp/runtime/include/transport/EtchPlainMailboxManager.h
@@ -110,7 +110,7 @@
   EtchTransportMessage* mTransport;
   capu::bool_t mUp;
   EtchHashTable<EtchLong, capu::SmartPointer<EtchMailbox> > mMailboxes;
-  capu::Mutex mMutex;
+  capu::Mutex mMailboxesMutex;
   EtchIdGenerator mIdGen;
 };
 
diff --git a/binding-cpp/runtime/src/main/support/EtchPlainMailbox.cpp b/binding-cpp/runtime/src/main/support/EtchPlainMailbox.cpp
index 5024733..628e296 100644
--- a/binding-cpp/runtime/src/main/support/EtchPlainMailbox.cpp
+++ b/binding-cpp/runtime/src/main/support/EtchPlainMailbox.cpp
@@ -22,12 +22,14 @@
 }
 
 EtchPlainMailbox::~EtchPlainMailbox() {
+  mQueueMutex.lock();
   while (!mQueue.isEmpty()) {
     EtchMailbox::EtchElement* element = NULL;
     if(ETCH_OK == mQueue.get(&element)) {
       delete element;
     }
   }
+  mQueueMutex.unlock();
 }
 
 EtchMailboxManager* EtchPlainMailbox::getMailboxManager() {
@@ -42,9 +44,9 @@
   status_t status;
   EtchMailbox::EtchElement* element = new EtchMailbox::EtchElement(sender, msg);
 
-  mMutex.lock();
+  mQueueMutex.lock();
   status = mQueue.put(element, -1);
-  mMutex.unlock();
+  mQueueMutex.unlock();
 
   if(status == ETCH_OK) {
      fireNotify();
@@ -62,7 +64,7 @@
   EtchObject* s;
   capu::bool_t c;
 
-  mMutex.lock();
+  mQueueMutex.lock();
   n = mNotify;
   s = mState;
   c = mQueue.isClosed();
@@ -70,13 +72,13 @@
   if (n != NULL) {
     n->mailboxStatus(this, s, c);
   }
-  mMutex.unlock();
+  mQueueMutex.unlock();
 }
 
 status_t EtchPlainMailbox::read(EtchMailbox::EtchElement*& result) {
-  mMutex.lock();
+  mQueueMutex.lock();
   status_t status = mQueue.get(&result);
-  mMutex.unlock();
+  mQueueMutex.unlock();
   if(ETCH_OK == status) {
     return ETCH_OK;
   }
@@ -85,9 +87,9 @@
 }
 
 status_t EtchPlainMailbox::read(EtchMailbox::EtchElement *& result, capu::int32_t maxDelay) {
-  mMutex.lock();
+  mQueueMutex.lock();
   status_t status = mQueue.get(&result, maxDelay);
-  mMutex.unlock();
+  mQueueMutex.unlock();
   if(status == ETCH_OK) {
     return ETCH_OK;
   }
@@ -96,15 +98,15 @@
 
 status_t EtchPlainMailbox::closeDelivery(capu::bool_t withNotification) {
 
-  mMutex.lock();
+  mQueueMutex.lock();
   if(mQueue.isClosed()) {
-    mMutex.unlock();
+    mQueueMutex.unlock();
     return ETCH_EINVAL;
   }
 
   mMailboxManager->unregisterMailbox(getMessageId());
   mQueue.close();
-  mMutex.unlock();
+  mQueueMutex.unlock();
 
   if (withNotification) {
     fireNotify();
@@ -136,10 +138,10 @@
 
   capu::bool_t isNotEmptyOrIsClosed;
 
-  mMutex.lock();
+  mQueueMutex.lock();
 
   if(mNotify != NULL) {
-    mMutex.unlock();
+    mQueueMutex.unlock();
     return ETCH_EINVAL;
   }
 
@@ -148,7 +150,7 @@
 
   isNotEmptyOrIsClosed = !mQueue.isEmpty() || mQueue.isClosed();
 
-  mMutex.unlock();
+  mQueueMutex.unlock();
 
   if(isNotEmptyOrIsClosed) {
     fireNotify();
@@ -167,32 +169,38 @@
     return ETCH_OK;
   }
 
-  mMutex.lock();
+  mQueueMutex.lock();
 
   if(mNotify !=  notify) {
-    mMutex.unlock();
+    mQueueMutex.unlock();
     return ETCH_EINVAL;
   }
 
   mNotify = NULL;
   mState = NULL;
 
-  mMutex.unlock();
+  mQueueMutex.unlock();
 
   return ETCH_OK;
 }
 
 capu::bool_t EtchPlainMailbox::isEmpty() {
+  mQueueMutex.lock();
   capu::bool_t res = mQueue.isEmpty();
+  mQueueMutex.unlock();
   return res;
 }
 
 capu::bool_t EtchPlainMailbox::isClosed() {
+  mQueueMutex.lock();
   capu::bool_t res = mQueue.isClosed();
+  mQueueMutex.unlock();
   return res;
 }
 
 capu::bool_t EtchPlainMailbox::isFull() {
+  mQueueMutex.lock();
   capu::bool_t res = mQueue.isFull();
+  mQueueMutex.unlock();
   return res;
 }
diff --git a/binding-cpp/runtime/src/main/transport/EtchPlainMailboxManager.cpp b/binding-cpp/runtime/src/main/transport/EtchPlainMailboxManager.cpp
index 1d670f6..4e59449 100644
--- a/binding-cpp/runtime/src/main/transport/EtchPlainMailboxManager.cpp
+++ b/binding-cpp/runtime/src/main/transport/EtchPlainMailboxManager.cpp
@@ -26,7 +26,7 @@
 }
 
 EtchPlainMailboxManager::~EtchPlainMailboxManager() {
-  mMutex.lock();
+  mMailboxesMutex.lock();
 
   EtchHashTable<EtchLong, capu::SmartPointer<EtchMailbox> >::Iterator it = mMailboxes.begin();
   EtchHashTable<EtchLong, capu::SmartPointer<EtchMailbox> >::HashTableEntry entry;
@@ -36,7 +36,7 @@
     entry.value->closeDelivery();
   }
 
-  mMutex.unlock();
+  mMailboxesMutex.unlock();
 }
 
 EtchTransportMessage* EtchPlainMailboxManager::getTransport() {
@@ -70,9 +70,9 @@
 
 status_t EtchPlainMailboxManager::unregisterMailbox(EtchLong mailboxId) {
   capu::SmartPointer<EtchMailbox> tmp = NULL;
-  mMutex.lock();
+  mMailboxesMutex.lock();
   mMailboxes.remove(mailboxId, &tmp);
-  mMutex.unlock();
+  mMailboxesMutex.unlock();
   return ETCH_OK;
 }
 
@@ -86,13 +86,13 @@
   if(msg->getInReplyToMessageId(msgid) == ETCH_OK) {
     capu::SmartPointer<EtchMailbox> mb = NULL;
     ETCH_LOG_DEBUG(mRuntime->getLogger(), mRuntime->getLogger().getMailboxContext(), "A message has been received as answer to message identified by msgid " << msgid);
-	mMutex.lock();
+	mMailboxesMutex.lock();
     if (getMailbox(msgid, mb) != ETCH_OK) {
-	  mMutex.unlock();
+	  mMailboxesMutex.unlock();
       ETCH_LOG_ERROR(mRuntime->getLogger(), mRuntime->getLogger().getMailboxContext(), "Mailbox for Message with msgid " << msgid << "has already been closed and removed. Dropping message.");
       return ETCH_ERROR;
     }
-    mMutex.unlock();
+    mMailboxesMutex.unlock();
     ETCH_LOG_DEBUG(mRuntime->getLogger(), mRuntime->getLogger().getMailboxContext(), "Message has been sent to respective mailbox");
 	status_t status = mb->message(sender, msg);
 	
@@ -122,21 +122,22 @@
 
   ETCH_LOG_DEBUG(mRuntime->getLogger(), mRuntime->getLogger().getMailboxContext(), "A mailbox has been created for msgid " << msgid);
   capu::SmartPointer<EtchMailbox> mb = new EtchPlainMailbox(this, msgid);
-  mMutex.lock();
+
+  mMailboxesMutex.lock();
   if (registerMailbox(mb) != ETCH_OK) {
     ETCH_LOG_ERROR(mRuntime->getLogger(), mRuntime->getLogger().getMailboxContext(), "Mailbox registration failed");
-    mMutex.unlock();
+    mMailboxesMutex.unlock();
     return ETCH_ERROR;
   }
 
   ETCH_LOG_DEBUG(mRuntime->getLogger(), mRuntime->getLogger().getMailboxContext(), "Message sending to Messagizer and registering a respective mailbox");
   if (mTransport->transportMessage(recipient, msg) == ETCH_OK) {
     result = mb;
-    mMutex.unlock();
+    mMailboxesMutex.unlock();
     return ETCH_OK;
   } else {
     mb->closeDelivery();
-    mMutex.unlock();
+    mMailboxesMutex.unlock();
     return ETCH_ERROR;
   }
 }
@@ -178,7 +179,7 @@
 }
 
 status_t EtchPlainMailboxManager::sessionNotify(capu::SmartPointer<EtchObject> event) {
-  mMutex.lock();
+  mMailboxesMutex.lock();
   if (event->equals(&EtchSession::UP())) {
     mUp = true;
     ETCH_LOG_TRACE(mRuntime->getLogger(), mRuntime->getLogger().getMailboxContext(), "Connection is up");
@@ -192,7 +193,7 @@
     }
     ETCH_LOG_TRACE(mRuntime->getLogger(), mRuntime->getLogger().getMailboxContext(), "Connection is down");
   }
-  mMutex.unlock();
+  mMailboxesMutex.unlock();
 
   status_t status;
   if(mSession != NULL) {