From 3c8e82cf69e524a83415677a43c2161d849d10df Mon Sep 17 00:00:00 2001
Message-Id: <3c8e82cf69e524a83415677a43c2161d849d10df.1348585382.git.ibell@...>
From: Ian Bell <ibell@...>
Date: Tue, 25 Sep 2012 15:32:47 +0100
Subject: [PATCH 1/3] Fix internal queue race condition
Added a lock around the internal queue creation to avoid multiple
instances being created and leaking on shutdown.
Signed-off-by: Ian Bell <ibell@...>
---
mama/c_cpp/src/c/bridge.c | 2 ++
mama/c_cpp/src/c/bridge.h | 3 +++
2 files changed, 5 insertions(+)
diff --git a/mama/c_cpp/src/c/bridge.c b/mama/c_cpp/src/c/bridge.c
index 25e1f34..01cbcc5 100644
--- a/mama/c_cpp/src/c/bridge.c
+++ b/mama/c_cpp/src/c/bridge.c
@@ -83,6 +83,7 @@ mamaBridgeImpl_getInternalEventQueue (mamaBridge bridgeImpl, mamaQueue* internal
return MAMA_STATUS_NO_BRIDGE_IMPL;
}
+ wlock_lock (impl->mLock);
if (!impl->mInternalEventQueue)
{
if (MAMA_STATUS_OK != mamaQueue_create (&impl->mInternalEventQueue,
@@ -101,6 +102,7 @@ mamaBridgeImpl_getInternalEventQueue (mamaBridge bridgeImpl, mamaQueue* internal
return MAMA_STATUS_NO_BRIDGE_IMPL;
}
}
+ wlock_unlock (impl->mLock);
*internalQueue = impl->mInternalEventQueue;
return MAMA_STATUS_OK;
diff --git a/mama/c_cpp/src/c/bridge.h b/mama/c_cpp/src/c/bridge.h
index 1e5ebc5..197eeb8 100644
--- a/mama/c_cpp/src/c/bridge.h
+++ b/mama/c_cpp/src/c/bridge.h
@@ -28,6 +28,7 @@
#include "mama/subscmsgtype.h"
#include "mamainternal.h"
#include "conflation/manager_int.h"
+#include "wlock.h"
#if defined(__cplusplus)
extern "C" {
@@ -71,6 +72,7 @@ do \
{ \
bridgeImpl->mClosure = NULL; \
bridgeImpl->mNativeMsgBridge = NULL; \
+ bridgeImpl->mLock = wlock_create(); \
/*mama.c function pointers*/ \
bridgeImpl->bridgeOpen = implIdentifier ## Bridge_open; \
bridgeImpl->bridgeClose = implIdentifier ## Bridge_close; \
@@ -701,6 +703,7 @@ typedef struct mamaBridgeImpl
/*Associate arbitrary data with a bridge impl. Needed for the C++ wrapper*/
void* mClosure;
+ wLock mLock;
/* The set of methods used to access/populate a message in native format */
mamaPayloadBridge mNativeMsgBridge;
--
1.7.9.5