Re: [Patch 1.1 1/1] OpenMAMA (C): Adding .gitignore to force git to skip known build artifacts in status summary
Mark Spielman
Hi Mike,
toggle quoted messageShow quoted text
I appreciate the feedback. Below is an updated patch. Let me know if there are any other suggested edits. Cheers, Mark --------- This patch introduces a .gitignore file to force git to skip known build artifacts when displaying status information. Signed-off-by: Mark Spielman <mark.spielman@...> --- iff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d018ef3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,76 @@ +# Compiled source # +################### +*.com +*.class +*.dll +*.exe +*.o +*.so +*.lo +*.la + +# Temporary Directories # +######################### +.dep* +.lib* + +# GNU Automake # +################ +Makefile +Makefile.in + +# Packages # +############ +# it's better to unpack these files and commit the raw source +# git has its own built in compression methods +*.7z +*.dmg +*.gz +*.iso +*.jar +*.rar +*.tar +*.zip + +# Logs and databases # +###################### +*.log +*.sql +*.sqlite + +# OS generated files # +###################### +.DS_Store* +ehthumbs.db +Icon? +Thumbs.db +*~ +*.swp + +# OpenMAMA Specific # +# ################### +common/c_cpp/aclocal.m4 +common/c_cpp/autom4te.cache/ +common/c_cpp/config.h +common/c_cpp/config.h.in +common/c_cpp/config.status +common/c_cpp/configure +common/c_cpp/etc/ +common/c_cpp/libtool +common/c_cpp/src/c/properties.c +common/c_cpp/src/c/version.h +common/c_cpp/stamp-h1 +mama/c_cpp/aclocal.m4 +mama/c_cpp/autom4te.cache/ +mama/c_cpp/config.h +mama/c_cpp/config.h.in +mama/c_cpp/config.status +mama/c_cpp/configure +mama/c_cpp/doc/c/ +mama/c_cpp/doxyconfig-c +mama/c_cpp/etc/ +mama/c_cpp/libtool +mama/c_cpp/src/c/bridge/solace/Makefile.am +mama/c_cpp/src/c/mama/version.h +mama/c_cpp/src/c/version.c +mama/c_cpp/stamp-h1
-----Original Message-----
From: openmama-dev-bounces@... [mailto:openmama-dev-bounces@...] On Behalf Of Michael Schonberg Sent: Tuesday, March 27, 2012 8:03 PM To: openmama-dev@... Subject: Re: [Openmama-dev] [Patch 1.1 1/1] OpenMAMA (C): Adding .gitignore to force git to skip known build artifacts in status summary This is very useful. I would remove mama/c_cpp/config.h.in~ and add *~ and *.swp for temporary files generated by vi. -Mike [snip] _______________________________________________ Openmama-dev mailing list Openmama-dev@... http://lists.openmama.org/listinfo/openmama-dev
|
|
Re: [Patch 1.1 1/1] OpenMAMA (C): Adding .gitignore to force git to skip known build artifacts in status summary
Michael Schonberg <mschonberg@...>
This is very useful.
I would remove mama/c_cpp/config.h.in~ and add *~ and *.swp for temporary files generated by vi. -Mike On 03/27/2012 01:53 PM, Mark Spielman wrote: This patch introduces a .gitignore file to force git to skip known build artifacts when displaying status information.# Temporary Files ################# *.swp *~ +# GNU Automake # +mama/c_cpp/config.status
|
|
Re: Getting a bridge build version
Michael Schonberg <mschonberg@...>
On 03/27/2012 01:12 PM, Mark Spielman wrote:
I'm interested in any best practices for getting a build version to report as part of the bridgeImpl->bridgeGetVersion() method. I've found what looks to be a reasonable version in the file: mama/c_cpp/config.h. I believe this is what AVIS is using. In OpenMAMA 1.1 it's currently set to:It is largely up to the bridge implementor; however, it makes sense to identify both the version of the bridge code and the underlying middleware if it is available. /* Version number of package */Avis does not provide version information through the API so the implementor simply used the MAMA version that was current at the time. Future releases of the Avis bridge will return "not implemented" for this method. Or it seems I could just reuse the version from mama/c_cpp/c/src/c/mama/version.h as the equivalent of a bridge build version. Any suggestions? I'd like to be able to track a version that identifies a particular build of bridge code to correlate this for bug tracking.Regards, -Mike
|
|
[Patch 1.1 1/1] OpenMAMA (C): Adding .gitignore to force git to skip known build artifacts in status summary
Mark Spielman
This patch introduces a .gitignore file to force git to skip known build artifacts when displaying status information.
Signed-off-by: Mark Spielman <mark.spielman@...> --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..182bfd9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,75 @@ +# Compiled source # +################### +*.com +*.class +*.dll +*.exe +*.o +*.so +*.lo +*.la + +# Temporary Directories # +######################### +.dep* +.lib* + +# GNU Automake # +################ +Makefile +Makefile.in + +# Packages # +############ +# it's better to unpack these files and commit the raw source +# git has its own built in compression methods +*.7z +*.dmg +*.gz +*.iso +*.jar +*.rar +*.tar +*.zip + +# Logs and databases # +###################### +*.log +*.sql +*.sqlite + +# OS generated files # +###################### +.DS_Store* +ehthumbs.db +Icon? +Thumbs.db + +# OpenMAMA Specific # +# ################### +common/c_cpp/aclocal.m4 +common/c_cpp/autom4te.cache/ +common/c_cpp/config.h +common/c_cpp/config.h.in +common/c_cpp/config.status +common/c_cpp/configure +common/c_cpp/etc/ +common/c_cpp/libtool +common/c_cpp/src/c/properties.c +common/c_cpp/src/c/version.h +common/c_cpp/stamp-h1 +mama/c_cpp/aclocal.m4 +mama/c_cpp/autom4te.cache/ +mama/c_cpp/config.h +mama/c_cpp/config.h.in +mama/c_cpp/config.h.in~ +mama/c_cpp/config.status +mama/c_cpp/configure +mama/c_cpp/doc/c/ +mama/c_cpp/doxyconfig-c +mama/c_cpp/etc/ +mama/c_cpp/libtool +mama/c_cpp/src/c/bridge/solace/Makefile.am +mama/c_cpp/src/c/mama/version.h +mama/c_cpp/src/c/version.c +mama/c_cpp/stamp-h1
|
|
Getting a bridge build version
Mark Spielman
I’m interested in any best practices for getting a build version to report as part of the bridgeImpl->bridgeGetVersion() method. I’ve found what looks to be a reasonable version in the file: mama/c_cpp/config.h. I believe this is what AVIS is using. In OpenMAMA 1.1 it’s currently set to:  /* Version number of package */ #define VERSION "5.0.3rc11"  Or it seems I could just reuse the version from mama/c_cpp/c/src/c/mama/version.h as the equivalent of a bridge build version. Any suggestions? I’d like to be able to track a version that identifies a particular build of bridge code to correlate this for bug tracking.  Cheers, Mark   Mark Spielman Development Lead, Solace Systems Professional Services  Â
|
|
Re: Bridge Error Code
Mike Schonberg <mschonberg@...>
Mark,  MAMA_STATUS_PLATFORM is used for generic bridge errors. It might be useful to add some more specific error codes as well.  Regards, -Mike  From:
openmama-dev-bounces@...
[mailto:openmama-dev-bounces@...] On Behalf Of Mark
Spielman  I am in the process of implementing a bridge support for a new middleware component in openMAMA. During implementation I have a need to return a sensible mama_status code for a generic bridge error. Something equivalent to handling unexpected internal errors. I see there’s the following in status.h:  /* No bridge */    MAMA_STATUS_NO_BRIDGE_IMPL             = 26,  But I’m looking more for something like: MAMA_STATUS_BRDIGE_INTERNAL_ERROR  Can you suggest what the appropriate code is. In general I will try to match up to existing codes wherever possible.  Cheers, Mark    Mark Spielman Development Lead, Solace Systems Professional Services   Please consider the environment before printing this email. Visit our website at http://www.nyse.com
|
|
Bridge Error Code
Mark Spielman
I am in the process of implementing a bridge support for a new middleware component in openMAMA. During implementation I have a need to return a sensible mama_status code for a generic bridge error. Something equivalent to handling unexpected internal errors. I see there’s the following in status.h:  /* No bridge */    MAMA_STATUS_NO_BRIDGE_IMPL             = 26,  But I’m looking more for something like: MAMA_STATUS_BRDIGE_INTERNAL_ERROR  Can you suggest what the appropriate code is. In general I will try to match up to existing codes wherever possible.  Cheers, Mark    Mark Spielman Development Lead, Solace Systems Professional Services  Â
|
|
[PATCH 4/4] Make sure that we load and unload bridges properly
Michael Schonberg <mschonberg@...>
From: Mike Schonberg <mschonberg@...>
These changes ensure that we hold the lock while opening and closing payload and messaging brdiges. Additionally, we store the shared library handles so we can close them when cleaning up. Signed-off-by: John Gray <jgray@...> --- mama/c_cpp/src/c/mama.c | 100 ++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 87 insertions(+), 13 deletions(-) diff --git a/mama/c_cpp/src/c/mama.c b/mama/c_cpp/src/c/mama.c index 2623f29..0657286 100644 --- a/mama/c_cpp/src/c/mama.c +++ b/mama/c_cpp/src/c/mama.c @@ -187,6 +187,11 @@ static mamaImpl gImpl = {{0}, {0}, {0}, {0}, 0, PTHREAD_MUTEX_INITIALIZER}; /* Private Function Prototypes. */ /* ************************************************************************* */ +static mama_status +mama_loadBridgeWithPathInternal (mamaBridge* impl, + const char* middlewareName, + const char* path, + uint8_t lock); /* Description : This function will free any memory associated with a * mamaApplicationContext object but will not free the @@ -332,8 +337,12 @@ static mama_status mamaInternal_loadStatsPublisher () } /* Will load the bridge if its not already loaded */ + /* Lock is alread acquired at this point */ if (MAMA_STATUS_OK != - (status = mama_loadBridge (&bridge, statsLogMiddlewareName))) + (status = mama_loadBridgeWithPathInternal (&bridge, + statsLogMiddlewareName, + NULL, + 0))) { mama_log (MAMA_LOG_LEVEL_ERROR, "mamaInternal_loadStatsLogger(): ", @@ -914,12 +923,12 @@ mama_openWithPropertiesCount (const char* path, mama_log (MAMA_LOG_LEVEL_SEVERE, "mama_openWithProperties(): " "Error connecting to Entitlements Server"); + pthread_mutex_unlock (&gImpl.myLock); mama_close(); if (count) *count = gImpl.myRefCount; - pthread_mutex_unlock (&gImpl.myLock); return result; } #endif /* WITH_ENTITLEMENTS */ @@ -1151,6 +1160,11 @@ mama_closeCount (unsigned int* count) /* mamaPayloadBridgeImpl* impl = (mamaPayloadBridgeImpl*) * gImpl.myPayloads [(uint8_t)payload];*/ gImpl.myPayloads[(uint8_t)payload] = NULL; + if(gImpl.myPayloadLibraries[(uint8_t)payload]) + { + closeSharedLib (gImpl.myPayloadLibraries[(uint8_t)payload]); + gImpl.myPayloadLibraries[(uint8_t)payload] = NULL; + } } gDefaultPayload = NULL; @@ -1250,8 +1264,10 @@ mama_closeCount (unsigned int* count) mamaMiddleware_convertToString (middleware)); } + gImpl.myBridges[middleware] = NULL; + closeSharedLib (gImpl.myBridgeLibraries[middleware]); + gImpl.myBridgeLibraries[middleware] = NULL; } - gImpl.myBridges[middleware] = NULL; } /* The properties must not be closed down until after the bridges have been destroyed. */ @@ -1796,9 +1812,11 @@ mamaInternal_registerBridge (mamaBridge bridge, middlewareName ? middlewareName : ""); return; } - + + pthread_mutex_lock (&gImpl.myLock); gImpl.myBridges[middleware] = bridge; ((mamaBridgeImpl*)(bridge))->mRefCount = 0; + pthread_mutex_unlock (&gImpl.myLock); } mama_status @@ -1813,8 +1831,9 @@ mama_setDefaultPayload (char id) } mama_status -mama_loadPayloadBridge (mamaPayloadBridge* impl, - const char* payloadName) +mama_loadPayloadBridgeInternal (mamaPayloadBridge* impl, + const char* payloadName, + uint8_t lock) { char bridgeImplName [256]; char initFuncName [256]; @@ -1829,6 +1848,9 @@ mama_loadPayloadBridge (mamaPayloadBridge* impl, snprintf (bridgeImplName, 256, "mama%simpl", payloadName); + if (lock) + pthread_mutex_lock (&gImpl.myLock); + bridgeLib = openSharedLib (bridgeImplName, NULL); if (!bridgeLib) @@ -1839,6 +1861,8 @@ mama_loadPayloadBridge (mamaPayloadBridge* impl, "Could not open payload bridge library [%s] [%s]", bridgeImplName ? bridgeImplName : "", getLibError()); + if (lock) + pthread_mutex_unlock (&gImpl.myLock); return MAMA_STATUS_NO_BRIDGE_IMPL; } @@ -1855,11 +1879,18 @@ mama_loadPayloadBridge (mamaPayloadBridge* impl, initFuncName ? initFuncName : "", bridgeImplName ? bridgeImplName : ""); closeSharedLib (bridgeLib); + + if (lock) + pthread_mutex_unlock (&gImpl.myLock); + return MAMA_STATUS_NO_BRIDGE_IMPL; } if (MAMA_STATUS_OK != (status = initFunc (impl, &payloadChar))) { + if (lock) + pthread_mutex_unlock (&gImpl.myLock); + return status; } @@ -1867,6 +1898,10 @@ mama_loadPayloadBridge (mamaPayloadBridge* impl, { mama_log (MAMA_LOG_LEVEL_ERROR, "mama_loadPayloadBridge(): Error in [%s] ", initFuncName); + + if (lock) + pthread_mutex_unlock (&gImpl.myLock); + return MAMA_STATUS_NO_BRIDGE_IMPL; } @@ -1876,7 +1911,11 @@ mama_loadPayloadBridge (mamaPayloadBridge* impl, "mama_loadPayloadBridge(): " "Payload bridge %s already loaded", payloadName); - return MAMA_STATUS_OK; + + if (lock) + pthread_mutex_unlock (&gImpl.myLock); + + return MAMA_STATUS_OK; } gImpl.myPayloads [(int)payloadChar] = *impl; @@ -1891,10 +1930,20 @@ mama_loadPayloadBridge (mamaPayloadBridge* impl, "mama_loadPayloadBridge(): " "Sucessfully loaded %s payload bridge from library [%s]", payloadName, bridgeImplName); + + if (lock) + pthread_mutex_unlock (&gImpl.myLock); return MAMA_STATUS_OK; } +mama_status +mama_loadPayloadBridge (mamaPayloadBridge* impl, + const char* payloadName) +{ + return mama_loadPayloadBridgeInternal (impl, payloadName, 1); +} + int mamaInternal_generateLbmStats () { @@ -1910,9 +1959,10 @@ mama_loadBridge (mamaBridge* impl, } mama_status -mama_loadBridgeWithPath (mamaBridge* impl, - const char* middlewareName, - const char* path) +mama_loadBridgeWithPathInternal (mamaBridge* impl, + const char* middlewareName, + const char* path, + uint8_t lock) { char bridgeImplName [256]; char initFuncName [256]; @@ -1934,15 +1984,19 @@ mama_loadBridgeWithPath (mamaBridge* impl, "mama_loadBridge(): Invalid middleware [%s]", middlewareName); } + + if (lock) + pthread_mutex_lock (&gImpl.myLock); /* Check if a bridge has already been initialized for the middleware */ if (gImpl.myBridges [middleware]) { *impl = gImpl.myBridges [middleware]; + if (lock) + pthread_mutex_unlock (&gImpl.myLock); return MAMA_STATUS_OK; } - snprintf (bridgeImplName, 256, "mama%simpl", middlewareName); @@ -1950,7 +2004,6 @@ mama_loadBridgeWithPath (mamaBridge* impl, if (!bridgeLib) { - if (path) { mama_log (MAMA_LOG_LEVEL_ERROR, @@ -1968,6 +2021,8 @@ mama_loadBridgeWithPath (mamaBridge* impl, bridgeImplName ? bridgeImplName : "", getLibError()); } + if (lock) + pthread_mutex_unlock (&gImpl.myLock); return MAMA_STATUS_NO_BRIDGE_IMPL; } @@ -1984,6 +2039,8 @@ mama_loadBridgeWithPath (mamaBridge* impl, initFuncName ? initFuncName : "", bridgeImplName ? bridgeImplName : ""); closeSharedLib (bridgeLib); + if (lock) + pthread_mutex_unlock (&gImpl.myLock); return MAMA_STATUS_NO_BRIDGE_IMPL; } @@ -1993,6 +2050,8 @@ mama_loadBridgeWithPath (mamaBridge* impl, { mama_log (MAMA_LOG_LEVEL_ERROR, "mama_loadBridge(): Error in [%s] ", initFuncName); + if (lock) + pthread_mutex_unlock (&gImpl.myLock); return MAMA_STATUS_NO_BRIDGE_IMPL; } @@ -2005,22 +2064,37 @@ mama_loadBridgeWithPath (mamaBridge* impl, result = ((mamaBridgeImpl*)(*impl))->bridgeOpen (*impl); if (MAMA_STATUS_OK != result) + { + if (lock) + pthread_mutex_unlock (&gImpl.myLock); return result; + } if (((mamaBridgeImpl*)(*impl))->bridgeGetDefaultPayloadId(&payloadName, &payloadId) == MAMA_STATUS_OK) { if (!gImpl.myPayloads [(uint8_t)payloadId]) { mamaPayloadBridge payloadImpl; - mama_loadPayloadBridge (&payloadImpl,payloadName); + mama_loadPayloadBridgeInternal (&payloadImpl,payloadName,0); } } gImpl.myBridges [middleware] = *impl; + gImpl.myBridgeLibraries [middleware] = bridgeLib; + if (lock) + pthread_mutex_unlock (&gImpl.myLock); return MAMA_STATUS_OK; } +mama_status +mama_loadBridgeWithPath (mamaBridge* impl, + const char* middlewareName, + const char* path) +{ + return mama_loadBridgeWithPathInternal(impl, middlewareName, path, 1); +} + /* * Function pointer type for calling getVersion in the wrapper */ -- 1.7.5.4
|
|
[PATCH 3/4] Added Per-bridge Reference Count
Michael Schonberg <mschonberg@...>
From: Mike Schonberg <mschonberg@...>
Added a reference count to mamaBridgeImpl struct. mama_start() and mama_stop() increment and decrement this reference count to determine when initialization is required and when the bridges can be unloaded. The internal registerBridge() method ensures that it is properly initialized to 0. Signed-off-by: John Gray <jgray@...> --- mama/c_cpp/src/c/bridge.h | 3 +++ mama/c_cpp/src/c/mama.c | 41 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/mama/c_cpp/src/c/bridge.h b/mama/c_cpp/src/c/bridge.h index 5a9588b..5ab7707 100644 --- a/mama/c_cpp/src/c/bridge.h +++ b/mama/c_cpp/src/c/bridge.h @@ -681,6 +681,9 @@ typedef mama_status */ typedef struct mamaBridgeImpl { + /* Used by mama_start() and mama_stop(). */ + unsigned int mRefCount; + /*The default event queue is now middleware specific. (Originally global)*/ mamaQueue mDefaultEventQueue; diff --git a/mama/c_cpp/src/c/mama.c b/mama/c_cpp/src/c/mama.c index 7b6add9..2623f29 100644 --- a/mama/c_cpp/src/c/mama.c +++ b/mama/c_cpp/src/c/mama.c @@ -1295,6 +1295,8 @@ mama_status mama_start (mamaBridge bridgeImpl) { mamaBridgeImpl* impl = (mamaBridgeImpl*)bridgeImpl; + mama_status rval = MAMA_STATUS_OK; + unsigned int prevRefCnt = 0; if (!impl) { @@ -1310,8 +1312,25 @@ mama_start (mamaBridge bridgeImpl) return MAMA_STATUS_INVALID_QUEUE; } - /*Delegate to the bridge specific implementation*/ - return impl->bridgeStart (impl->mDefaultEventQueue); + pthread_mutex_lock(&gImpl.myLock); + prevRefCnt = impl->mRefCount++; + pthread_mutex_unlock(&gImpl.myLock); + + if (prevRefCnt > 0) + return MAMA_STATUS_OK; + + /* Delegate to the bridge specific implementation */ + /* Can't hold lock because bridgeStart blocks */ + rval = impl->bridgeStart (impl->mDefaultEventQueue); + + if (rval != MAMA_STATUS_OK) + { + pthread_mutex_lock(&gImpl.myLock); + impl->mRefCount--; + pthread_mutex_unlock(&gImpl.myLock); + } + + return rval; } struct startBackgroundClosure @@ -1385,6 +1404,7 @@ mama_status mama_stop (mamaBridge bridgeImpl) { mamaBridgeImpl* impl = (mamaBridgeImpl*)bridgeImpl; + mama_status rval = MAMA_STATUS_OK; if (!impl) { @@ -1402,7 +1422,19 @@ mama_stop (mamaBridge bridgeImpl) } /*Delegate to the bridge specific implementation*/ - return impl->bridgeStop (impl->mDefaultEventQueue); + pthread_mutex_lock(&gImpl.myLock); + if (impl->mRefCount > 0) + { + impl->mRefCount--; + if(impl->mRefCount == 0) + { + rval = impl->bridgeStop (impl->mDefaultEventQueue); + if (MAMA_STATUS_OK != rval) + impl->mRefCount++; + } + } + pthread_mutex_unlock(&gImpl.myLock); + return rval; } /** @@ -1749,7 +1781,6 @@ enableEntitlements (const char **servers) #endif - void mamaInternal_registerBridge (mamaBridge bridge, const char* middlewareName) @@ -1767,6 +1798,7 @@ mamaInternal_registerBridge (mamaBridge bridge, } gImpl.myBridges[middleware] = bridge; + ((mamaBridgeImpl*)(bridge))->mRefCount = 0; } mama_status @@ -1779,6 +1811,7 @@ mama_setDefaultPayload (char id) return MAMA_STATUS_OK; } + mama_status mama_loadPayloadBridge (mamaPayloadBridge* impl, const char* payloadName) -- 1.7.5.4
|
|
[PATCH 2/4] Add mama_openWithPropertiesCount() and mama_closeCount()
Michael Schonberg <mschonberg@...>
From: Mike Schonberg <mschonberg@...>
These methods take an additonal unsigned int* parameter that upon return contains the the reference count for mama_openXXX() and mama_closeXXX(). This allows applications to performa one-time global initialization when the int is 1 and mama_openWithPropertiesCount() returns MAMA_STATUS_OK. Likewise applications can clean up global data when the count is zero and mama_closeCount() returns MAMA_STATUS_OK. Signed-off-by: John Gray <jgray@...> --- mama/c_cpp/src/c/mama.c | 58 +++++++++++++++++++++++++++++++++++------ mama/c_cpp/src/c/mama/mama.h | 45 ++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 9 deletions(-) diff --git a/mama/c_cpp/src/c/mama.c b/mama/c_cpp/src/c/mama.c index cecfa4a..7b6add9 100644 --- a/mama/c_cpp/src/c/mama.c +++ b/mama/c_cpp/src/c/mama.c @@ -643,8 +643,9 @@ mamaInternal_getDefaultPayload (void) } mama_status -mama_openWithProperties (const char* path, - const char* filename) +mama_openWithPropertiesCount (const char* path, + const char* filename, + unsigned int* count) { mama_status result = MAMA_STATUS_OK; mama_size_t numBridges = 0; @@ -695,6 +696,10 @@ mama_openWithProperties (const char* path, { if (MAMA_STATUS_OK == result) gImpl.myRefCount++; + + if (count) + *count = gImpl.myRefCount; + pthread_mutex_unlock (&gImpl.myLock); return result; } @@ -757,6 +762,9 @@ mama_openWithProperties (const char* path, mama_log (MAMA_LOG_LEVEL_ERROR, "mama_openWithProperties(): " "Could not create stats generator."); + if (count) + *count = gImpl.myRefCount; + pthread_mutex_unlock (&gImpl.myLock); return result; } @@ -874,6 +882,9 @@ mama_openWithProperties (const char* path, mama_log (MAMA_LOG_LEVEL_SEVERE, "mama_openWithProperties(): " "At least one bridge must be specified"); + if (count) + *count = gImpl.myRefCount; + pthread_mutex_unlock (&gImpl.myLock); return MAMA_STATUS_NO_BRIDGE_IMPL; } @@ -883,6 +894,9 @@ mama_openWithProperties (const char* path, mama_log (MAMA_LOG_LEVEL_SEVERE, "mama_openWithProperties(): " "At least one payload must be specified"); + if (count) + *count = gImpl.myRefCount; + pthread_mutex_unlock (&gImpl.myLock); return MAMA_STATUS_NO_BRIDGE_IMPL; } @@ -901,6 +915,10 @@ mama_openWithProperties (const char* path, "mama_openWithProperties(): " "Error connecting to Entitlements Server"); mama_close(); + + if (count) + *count = gImpl.myRefCount; + pthread_mutex_unlock (&gImpl.myLock); return result; } @@ -938,6 +956,8 @@ mama_openWithProperties (const char* path, if (MAMA_STATUS_OK != (result = mamaBridgeImpl_getInternalEventQueue (bridge, &statsGenQueue))) { + if (count) + *count = gImpl.myRefCount; pthread_mutex_unlock (&gImpl.myLock); return result; } @@ -948,6 +968,8 @@ mama_openWithProperties (const char* path, mama_log (MAMA_LOG_LEVEL_ERROR, "mama_openWithProperties(): " "Could not set queue for stats generator."); + if (count) + *count = gImpl.myRefCount; pthread_mutex_unlock (&gImpl.myLock); return result; } @@ -957,12 +979,16 @@ mama_openWithProperties (const char* path, mama_log (MAMA_LOG_LEVEL_ERROR, "mama_openWithProperties(): " "Failed to enable stats logging"); + if (count) + *count = gImpl.myRefCount; pthread_mutex_unlock (&gImpl.myLock); return result; } } gImpl.myRefCount++; + if (count) + *count = gImpl.myRefCount; pthread_mutex_unlock (&gImpl.myLock); return result; } @@ -972,7 +998,14 @@ mama_open () { /*Passing NULL as path and filename will result in the default behaviour - mama.properties on $WOMBAT_PATH*/ - return mama_openWithProperties (NULL, NULL); + return mama_openWithPropertiesCount (NULL, NULL, NULL); +} + +mama_status +mama_openWithProperties (const char* path, + const char* filename) +{ + return mama_openWithPropertiesCount (path, filename, NULL); } mama_status @@ -1079,7 +1112,7 @@ mama_getVersion (mamaBridge bridgeImpl) } mama_status -mama_close () +mama_closeCount (unsigned int* count) { mama_status result = MAMA_STATUS_OK; mamaMiddleware middleware = 0; @@ -1088,6 +1121,8 @@ mama_close () pthread_mutex_lock (&gImpl.myLock); if (gImpl.myRefCount == 0) { + if (count) + *count = gImpl.myRefCount; pthread_mutex_unlock (&gImpl.myLock); return MAMA_STATUS_OK; } @@ -1113,11 +1148,8 @@ mama_close () /* Look for a bridge for each of the payloads and close them */ for (payload = 0; payload != MAMA_PAYLOAD_MAX; ++payload) { - mamaPayloadBridgeImpl* impl = (mamaPayloadBridgeImpl*) gImpl.myPayloads [(uint8_t)payload]; - if (impl) - { - - } + /* mamaPayloadBridgeImpl* impl = (mamaPayloadBridgeImpl*) + * gImpl.myPayloads [(uint8_t)payload];*/ gImpl.myPayloads[(uint8_t)payload] = NULL; } @@ -1244,10 +1276,18 @@ mama_close () mama_freeAppContext(&appContext); } + if (count) + *count = gImpl.myRefCount; pthread_mutex_unlock (&gImpl.myLock); return result; } +mama_status +mama_close (void) +{ + return mama_closeCount (NULL); +} + /** * Start processing messages. */ diff --git a/mama/c_cpp/src/c/mama/mama.h b/mama/c_cpp/src/c/mama/mama.h index 658bce6..557ac2c 100644 --- a/mama/c_cpp/src/c/mama/mama.h +++ b/mama/c_cpp/src/c/mama/mama.h @@ -220,6 +220,40 @@ extern "C" extern mama_status mama_openWithProperties (const char* path, const char* filename); + /** + * Initialize MAMA. + * + * Allows users of the API to override the default behavior of mama_open() + * where a file mama.properties is required to be located in the directory + * specified by \$WOMBAT_PATH. + * + * The properties file must have the same structure as a standard + * mama.properties file. + * + * If null is passed as the path the API will look for the properties file on + * the \$WOMBAT_PATH. + * + * If null is passed as the filename the API will look for the default + * filename of mama.properties. + * + * The count value on return will be the number of times that mama_openXxx() + * has ben invoked successfully. Applicatiins can use this to perform + * one-time initialization when the value is 1 and the return is + * MAMA_STATUS_OK + * + * @param path Fully qualified path to the directory containing the properties + * file + * @param filename The name of the file containing MAMA properties. + * @param count The number of times mama_OpenXXX() has been called + * successfully. + * + * @return mama_status Whether the call was successful or not. + */ + MAMAExpDLL + extern mama_status + mama_openWithPropertiesCount (const char* path, + const char* filename, + unsigned int* count); /** * Set a specific property for the API. @@ -291,6 +325,17 @@ extern "C" MAMAExpDLL extern mama_status mama_close (void); + + /** + * Close MAMA and free all associated resource. + * + * @param count Filled with the number of times mama has been opened + * successfully. Applications can perform global one-time cleanup when this + * value is 0 and the return value is MAMA_STATUS_OK. + */ + MAMAExpDLL + extern mama_status + mama_closeCount (unsigned int* count); /** * Return the version information for the library. -- 1.7.5.4
|
|
[PATCH 1/4] Added locking around mama_open() and mama_close()
Michael Schonberg <mschonberg@...>
From: Mike Schonberg <mschonberg@...>
Improved the reference counting logic and added locking around mama_open() and mama_close(). The change ensures that all initialization (one-time) and cleanup only occurs once. It also ensures that the reference count never goes belowe zero. Signed-off-by: John Gray <jgray@...> --- mama/c_cpp/src/c/mama.c | 39 ++++++++++++++++++++++++++++----------- 1 files changed, 28 insertions(+), 11 deletions(-) diff --git a/mama/c_cpp/src/c/mama.c b/mama/c_cpp/src/c/mama.c index 4142c16..cecfa4a 100644 --- a/mama/c_cpp/src/c/mama.c +++ b/mama/c_cpp/src/c/mama.c @@ -654,6 +654,8 @@ mama_openWithProperties (const char* path, const char* statsLogging = "false"; const char* catchCallbackExceptions = NULL; + pthread_mutex_lock (&gImpl.myLock); + if (pthread_key_create(&last_err_key, NULL) != 0) { mama_log (MAMA_LOG_LEVEL_NORMAL, "WARNING!!! - CANNOT ALLOCATE KEY FOR ERRORS"); @@ -689,7 +691,14 @@ mama_openWithProperties (const char* path, "********************************************************"); #endif - if (gImpl.myRefCount++) return result; + if (0 != gImpl.myRefCount) + { + if (MAMA_STATUS_OK == result) + gImpl.myRefCount++; + pthread_mutex_unlock (&gImpl.myLock); + return result; + } + /* Code after this point is one-time initialization */ #ifdef WITH_INACTIVE_CHECK mama_log (MAMA_LOG_LEVEL_WARN, @@ -748,10 +757,10 @@ mama_openWithProperties (const char* path, mama_log (MAMA_LOG_LEVEL_ERROR, "mama_openWithProperties(): " "Could not create stats generator."); + pthread_mutex_unlock (&gImpl.myLock); return result; } - globalLogging = properties_Get (gProperties, "mama.statslogging.global.logging"); globalPublishing = properties_Get (gProperties, "mama.statslogging.global.publishing"); transportLogging = properties_Get (gProperties, "mama.statslogging.transport.logging"); @@ -842,7 +851,6 @@ mama_openWithProperties (const char* path, } } - if (mamaInternal_statsPublishingEnabled()) { mamaInternal_loadStatsPublisher(); @@ -866,16 +874,16 @@ mama_openWithProperties (const char* path, mama_log (MAMA_LOG_LEVEL_SEVERE, "mama_openWithProperties(): " "At least one bridge must be specified"); + pthread_mutex_unlock (&gImpl.myLock); return MAMA_STATUS_NO_BRIDGE_IMPL; } if (!gDefaultPayload) { - - mama_log (MAMA_LOG_LEVEL_SEVERE, "mama_openWithProperties(): " "At least one payload must be specified"); + pthread_mutex_unlock (&gImpl.myLock); return MAMA_STATUS_NO_BRIDGE_IMPL; } @@ -893,6 +901,7 @@ mama_openWithProperties (const char* path, "mama_openWithProperties(): " "Error connecting to Entitlements Server"); mama_close(); + pthread_mutex_unlock (&gImpl.myLock); return result; } #endif /* WITH_ENTITLEMENTS */ @@ -929,6 +938,7 @@ mama_openWithProperties (const char* path, if (MAMA_STATUS_OK != (result = mamaBridgeImpl_getInternalEventQueue (bridge, &statsGenQueue))) { + pthread_mutex_unlock (&gImpl.myLock); return result; } } @@ -938,6 +948,7 @@ mama_openWithProperties (const char* path, mama_log (MAMA_LOG_LEVEL_ERROR, "mama_openWithProperties(): " "Could not set queue for stats generator."); + pthread_mutex_unlock (&gImpl.myLock); return result; } @@ -946,10 +957,13 @@ mama_openWithProperties (const char* path, mama_log (MAMA_LOG_LEVEL_ERROR, "mama_openWithProperties(): " "Failed to enable stats logging"); + pthread_mutex_unlock (&gImpl.myLock); return result; } } + gImpl.myRefCount++; + pthread_mutex_unlock (&gImpl.myLock); return result; } @@ -1071,7 +1085,14 @@ mama_close () mamaMiddleware middleware = 0; int payload = 0; - if( !--gImpl.myRefCount ) + pthread_mutex_lock (&gImpl.myLock); + if (gImpl.myRefCount == 0) + { + pthread_mutex_unlock (&gImpl.myLock); + return MAMA_STATUS_OK; + } + + if (!--gImpl.myRefCount) { #ifdef WITH_ENTITLEMENTS if( gEntitlementClient != 0 ) @@ -1120,7 +1141,6 @@ mama_close () gUnknownMsgStat = NULL; } - if (gMessageStat) { mamaStat_destroy (gMessageStat); @@ -1224,10 +1244,7 @@ mama_close () mama_freeAppContext(&appContext); } - if (gImpl.myRefCount < 0) - { - gImpl.myRefCount = 0; - } + pthread_mutex_unlock (&gImpl.myLock); return result; } -- 1.7.5.4
|
|
[PATCH] MAMA: Move global bridge data to struct
Michael Schonberg <mschonberg@...>
From: Mike Schonberg <mschonberg@...>
This is in preparation for adding improved reference counting and locking around mama_open(), and mama_close() to enable them to be called safely from multi-threaded applications. A number of compiler warnings are also fixed. Signed-off-by: John Gray <jgray@...> --- mama/c_cpp/src/c/mama.c | 106 +++++++++++++++++++++++++++++------------------ 1 files changed, 66 insertions(+), 40 deletions(-) diff --git a/mama/c_cpp/src/c/mama.c b/mama/c_cpp/src/c/mama.c index ee0d6a0..4142c16 100644 --- a/mama/c_cpp/src/c/mama.c +++ b/mama/c_cpp/src/c/mama.c @@ -128,7 +128,6 @@ static const char* gHostName = NULL; static void lookupIPAddress (void); -static int gRefCount = 0; wproperty_t gProperties = 0; static mamaStatsLogger gStatsPublisher = NULL; @@ -148,11 +147,9 @@ mamaStat gRvMsgsStat; #define MAMA_PAYLOAD_MAX CHAR_MAX -static mamaBridge gMamaBridges [MAMA_MIDDLEWARE_MAX]; -static mamaPayloadBridge gMamaPayloads [MAMA_PAYLOAD_MAX]; static mamaPayloadBridge gDefaultPayload = NULL; -pthread_key_t last_err_key; +static pthread_key_t last_err_key; /** * struct mamaApplicationGroup @@ -164,16 +161,39 @@ typedef struct mamaAppContext_ const char* myApplicationClass; } mamaApplicationContext; +/** + * This structure contains data needed to control starting and stopping of + * mama. + * + * TODO: Access to this structure will ultimately be protected by a reference + * count and a lock. + */ +typedef struct mamaImpl_ +{ + mamaBridge myBridges[MAMA_MIDDLEWARE_MAX]; + mamaPayloadBridge myPayloads[MAMA_PAYLOAD_MAX]; + LIB_HANDLE myBridgeLibraries[MAMA_MIDDLEWARE_MAX]; + LIB_HANDLE myPayloadLibraries[MAMA_PAYLOAD_MAX]; + unsigned int myRefCount; + pthread_mutex_t myLock; +} mamaImpl; static mamaApplicationContext appContext; static char mama_ver_string[256]; +static mamaImpl gImpl = {{0}, {0}, {0}, {0}, 0, PTHREAD_MUTEX_INITIALIZER}; + +/* ************************************************************************* */ +/* Private Function Prototypes. */ +/* ************************************************************************* */ + + /* Description : This function will free any memory associated with a * mamaApplicationContext object but will not free the * object itself. * Arguments : context [I] The context object to free. */ -void +static void mama_freeAppContext(mamaApplicationContext *context) { /* Only continue if the object is valid. */ @@ -348,7 +368,7 @@ mamaInternal_createStatsPublisher () statsLogMiddlewareName = "wmw"; } - bridge = gMamaBridges[mamaMiddleware_convertFromString (statsLogMiddlewareName)]; + bridge = gImpl.myBridges[mamaMiddleware_convertFromString (statsLogMiddlewareName)]; if (MAMA_STATUS_OK != (result = mamaBridgeImpl_getInternalEventQueue (bridge, &queue))) @@ -596,7 +616,7 @@ mamaInternal_findBridge () for (middleware = 0; middleware < MAMA_MIDDLEWARE_MAX; middleware++) { - bridge = gMamaBridges [middleware]; + bridge = gImpl.myBridges [middleware]; if (bridge != NULL) { @@ -610,9 +630,10 @@ mamaInternal_findBridge () mamaPayloadBridge mamaInternal_findPayload (char id) { - if (('\0' == id) || (MAMA_PAYLOAD_MAX < id)) return NULL; + if ('\0' == id) + return NULL; - return gMamaPayloads[(uint8_t)id]; + return gImpl.myPayloads[(uint8_t)id]; } mamaPayloadBridge @@ -668,7 +689,7 @@ mama_openWithProperties (const char* path, "********************************************************"); #endif - if (gRefCount++) return result; + if (gImpl.myRefCount++) return result; #ifdef WITH_INACTIVE_CHECK mama_log (MAMA_LOG_LEVEL_WARN, @@ -831,10 +852,10 @@ mama_openWithProperties (const char* path, /* Look for a bridge for each of the middlewares and open them */ for (middleware = 0; middleware != MAMA_MIDDLEWARE_MAX; ++middleware) { - mamaBridgeImpl* impl = (mamaBridgeImpl*) gMamaBridges [middleware]; + mamaBridgeImpl* impl = (mamaBridgeImpl*) gImpl.myBridges [middleware]; if (impl) { - mama_log (MAMA_LOG_LEVEL_FINE, mama_getVersion (gMamaBridges[middleware])); + mama_log (MAMA_LOG_LEVEL_FINE, mama_getVersion (gImpl.myBridges[middleware])); mamaQueue_enableStats(impl->mDefaultEventQueue); ++numBridges; } @@ -903,7 +924,7 @@ mama_openWithProperties (const char* path, statsMiddleware = "wmw"; } - bridge = gMamaBridges[mamaMiddleware_convertFromString (statsMiddleware)]; + bridge = gImpl.myBridges[mamaMiddleware_convertFromString (statsMiddleware)]; if (MAMA_STATUS_OK != (result = mamaBridgeImpl_getInternalEventQueue (bridge, &statsGenQueue))) @@ -1050,7 +1071,7 @@ mama_close () mamaMiddleware middleware = 0; int payload = 0; - if( !--gRefCount ) + if( !--gImpl.myRefCount ) { #ifdef WITH_ENTITLEMENTS if( gEntitlementClient != 0 ) @@ -1064,19 +1085,19 @@ mama_close () for (middleware = 0; middleware != MAMA_MIDDLEWARE_MAX; ++middleware) { - mamaBridge bridge = gMamaBridges[middleware]; + mamaBridge bridge = gImpl.myBridges[middleware]; if (bridge) mamaBridgeImpl_stopInternalEventQueue (bridge); } /* Look for a bridge for each of the payloads and close them */ for (payload = 0; payload != MAMA_PAYLOAD_MAX; ++payload) { - mamaPayloadBridgeImpl* impl = (mamaPayloadBridgeImpl*) gMamaPayloads [(uint8_t)payload]; + mamaPayloadBridgeImpl* impl = (mamaPayloadBridgeImpl*) gImpl.myPayloads [(uint8_t)payload]; if (impl) { } - gMamaPayloads[(uint8_t)payload] = NULL; + gImpl.myPayloads[(uint8_t)payload] = NULL; } gDefaultPayload = NULL; @@ -1166,11 +1187,11 @@ mama_close () /* Look for a bridge for each of the middlewares and close them */ for (middleware = 0; middleware != MAMA_MIDDLEWARE_MAX; ++middleware) { - mamaBridgeImpl* impl = (mamaBridgeImpl*) gMamaBridges [middleware]; + mamaBridgeImpl* impl = (mamaBridgeImpl*) gImpl.myBridges [middleware]; if (impl) { if (MAMA_STATUS_OK != ( - (result = impl->bridgeClose (gMamaBridges[middleware])))) + (result = impl->bridgeClose (gImpl.myBridges[middleware])))) { mama_log (MAMA_LOG_LEVEL_ERROR, "mama_close(): Error closing %s bridge.", @@ -1178,7 +1199,7 @@ mama_close () } } - gMamaBridges[middleware] = NULL; + gImpl.myBridges[middleware] = NULL; } /* The properties must not be closed down until after the bridges have been destroyed. */ @@ -1203,9 +1224,9 @@ mama_close () mama_freeAppContext(&appContext); } - if (gRefCount < 0) + if (gImpl.myRefCount < 0) { - gRefCount = 0; + gImpl.myRefCount = 0; } return result; } @@ -1339,10 +1360,10 @@ mama_stopAll (void) /* Look for a bridge for each of the middlewares and open them */ for (middleware = 0; middleware != MAMA_MIDDLEWARE_MAX; ++middleware) { - mamaBridgeImpl* impl = (mamaBridgeImpl*) gMamaBridges [middleware]; + mamaBridgeImpl* impl = (mamaBridgeImpl*) gImpl.myBridges [middleware]; if (impl) { - status = mama_stop (gMamaBridges[middleware]); + status = mama_stop (gImpl.myBridges[middleware]); if (MAMA_STATUS_OK != status) { mama_log (MAMA_LOG_LEVEL_ERROR, @@ -1676,8 +1697,10 @@ void mamaInternal_registerBridge (mamaBridge bridge, const char* middlewareName) { - mamaMiddleware middleware = - mamaMiddleware_convertFromString (middlewareName); + mamaMiddleware middleware; + + middleware = mamaMiddleware_convertFromString (middlewareName); + if (middleware >= MAMA_MIDDLEWARE_MAX) { mama_log (MAMA_LOG_LEVEL_SEVERE, @@ -1686,15 +1709,16 @@ mamaInternal_registerBridge (mamaBridge bridge, return; } - gMamaBridges [middleware] = bridge; + gImpl.myBridges[middleware] = bridge; } mama_status mama_setDefaultPayload (char id) { - if (('\0' == id) || (MAMA_PAYLOAD_MAX < id) || gMamaPayloads[(uint8_t)id] == NULL) return MAMA_STATUS_NULL_ARG; + if ('\0' == id || gImpl.myPayloads[(uint8_t)id] == NULL) + return MAMA_STATUS_NULL_ARG; - gDefaultPayload = gMamaPayloads[(uint8_t)id]; + gDefaultPayload = gImpl.myPayloads[(uint8_t)id]; return MAMA_STATUS_OK; } @@ -1756,7 +1780,7 @@ mama_loadPayloadBridge (mamaPayloadBridge* impl, return MAMA_STATUS_NO_BRIDGE_IMPL; } - if (gMamaPayloads [payloadChar]) + if (gImpl.myPayloads [(int)payloadChar]) { mama_log (MAMA_LOG_LEVEL_NORMAL, "mama_loadPayloadBridge(): " @@ -1765,7 +1789,8 @@ mama_loadPayloadBridge (mamaPayloadBridge* impl, return MAMA_STATUS_OK; } - gMamaPayloads [payloadChar] = *impl; + gImpl.myPayloads [(int)payloadChar] = *impl; + gImpl.myPayloadLibraries [(int)payloadChar] = bridgeLib; if (!gDefaultPayload) { @@ -1804,14 +1829,15 @@ mama_loadBridgeWithPath (mamaBridge* impl, LIB_HANDLE bridgeLib = NULL; bridge_createImpl initFunc = NULL; char* payloadName = NULL; - char payloadId = NULL; + char payloadId = '\0'; mama_status result = MAMA_STATUS_OK; - mamaMiddleware middleware = - mamaMiddleware_convertFromString (middlewareName); + mamaMiddleware middleware = 0; if (!impl) return MAMA_STATUS_NULL_ARG; + middleware = mamaMiddleware_convertFromString (middlewareName); + if (middleware >= MAMA_MIDDLEWARE_MAX) { mama_log (MAMA_LOG_LEVEL_ERROR, @@ -1820,9 +1846,9 @@ mama_loadBridgeWithPath (mamaBridge* impl, } /* Check if a bridge has already been initialized for the middleware */ - if (gMamaBridges [middleware]) + if (gImpl.myBridges [middleware]) { - *impl = gMamaBridges [middleware]; + *impl = gImpl.myBridges [middleware]; return MAMA_STATUS_OK; } @@ -1844,7 +1870,6 @@ mama_loadBridgeWithPath (mamaBridge* impl, bridgeImplName ? bridgeImplName : "", getLibError()); } - else { mama_log (MAMA_LOG_LEVEL_ERROR, @@ -1889,18 +1914,19 @@ mama_loadBridgeWithPath (mamaBridge* impl, result = ((mamaBridgeImpl*)(*impl))->bridgeOpen (*impl); - if (MAMA_STATUS_OK != result) return result; + if (MAMA_STATUS_OK != result) + return result; if (((mamaBridgeImpl*)(*impl))->bridgeGetDefaultPayloadId(&payloadName, &payloadId) == MAMA_STATUS_OK) { - if (!gMamaPayloads [(uint8_t)payloadId]) + if (!gImpl.myPayloads [(uint8_t)payloadId]) { mamaPayloadBridge payloadImpl; mama_loadPayloadBridge (&payloadImpl,payloadName); } } - gMamaBridges [middleware] = *impl; + gImpl.myBridges [middleware] = *impl; return MAMA_STATUS_OK; } -- 1.7.5.4
|
|
[PATCH] Added mamaTransportImpl_setAdvisoryCauseAndPlatformInfo()
Michael Schonberg <mschonberg@...>
From: Mike Schonberg <mschonberg@...>
This method allows bridges to pass middleware specific details regarding errors and events. Signed-off-by: John Gray <jgray@...> --- mama/c_cpp/src/c/transport.c | 67 +++++++++++++++++++++++--------------- mama/c_cpp/src/c/transportimpl.h | 39 ++++++++++++++++++--- 2 files changed, 74 insertions(+), 32 deletions(-) diff --git a/mama/c_cpp/src/c/transport.c b/mama/c_cpp/src/c/transport.c index 95e912c..20ee0cc 100644 --- a/mama/c_cpp/src/c/transport.c +++ b/mama/c_cpp/src/c/transport.c @@ -1960,32 +1960,6 @@ mamaTransportImpl_unsetAllPossiblyStale (mamaTransport transport) } } -/** - * Return the cause and platform info for the last message processed on the - * transport. - * - * @param transport The transport. - * @param cause To return the cause. - * @param platformInfo To return the bridge specific info, under no circumstances - * should the returned object be deleted. - */ -void -mamaTransportImpl_getAdvisoryCauseAndPlatformInfo (mamaTransport transport, - short* cause, - const void** platformInfo) -{ - if (!self) - { - mama_log (MAMA_LOG_LEVEL_ERROR, - "mamaTransportImpl_getAdvisoryCauseAndPlatformInfo (): " - "NULL transport."); - return; - } - - *cause = self->mCause; - *platformInfo = self->mPlatformInfo; -} - void mamaTransportImpl_getTransportIndex (mamaTransport transport, int* transportIndex) @@ -2363,3 +2337,44 @@ mama_status mamaTransport_removePublisher (mamaTransport transport, void *handle return MAMA_STATUS_OK; } +/* *************************************************** */ +/* Internal Functions. */ +/* *************************************************** */ + +void mamaTransportImpl_getAdvisoryCauseAndPlatformInfo(mamaTransport transport, + short *cause, const void **platformInfo) +{ + /* Get the impl. */ + transportImpl *impl = (transportImpl *)transport; + if(NULL != impl) + { + /* Return the cause. */ + *cause = impl->mCause; + *platformInfo = impl->mPlatformInfo; + } + else + { + mama_log (MAMA_LOG_LEVEL_ERROR, + "mamaTransportImpl_getAdvisoryCauseAndPlatformInfo(): NULL " + "transport."); + } +} + +void mamaTransportImpl_setAdvisoryCauseAndPlatformInfo (mamaTransport transport, + short cause, const void *platformInfo) +{ + /* Get the impl. */ + transportImpl *impl = (transportImpl *)transport; + if(NULL != impl) + { + /* Set the cause. */ + impl->mCause = cause; + impl->mPlatformInfo = (void*)platformInfo; + } + else + { + mama_log (MAMA_LOG_LEVEL_ERROR, + "mamaTransportImpl_setAdvisoryCauseAndPlatformInfo(): NULL " + "transport."); + } +} diff --git a/mama/c_cpp/src/c/transportimpl.h b/mama/c_cpp/src/c/transportimpl.h index cf4b3d0..5ae83c6 100644 --- a/mama/c_cpp/src/c/transportimpl.h +++ b/mama/c_cpp/src/c/transportimpl.h @@ -158,12 +158,6 @@ MAMAExpDLL extern void mamaTransportImpl_unsetAllPossiblyStale (mamaTransport tport); -MAMAExpDLL -extern void -mamaTransportImpl_getAdvisoryCauseAndPlatformInfo (mamaTransport tport, - short* cause, - const void** platformInfo); - /* Get the bridge impl associated with the specified transport. This will be how other objects gain access to the bridge. @@ -251,4 +245,37 @@ preInitialScheme mamaTransportImpl_getPreInitialScheme (mamaTransport transport) } #endif + +/** + * This function will return the cause and platform info for the last message + * processed on the transport. + * + * @param[in] transport The transport. + * @param[out] cause To return the cause. + * @param[out] platformInfo To return the bridge specific info, under no + * circumstances should the returned object be deleted. + * + */ +MAMAExpDLL +extern void +mamaTransportImpl_getAdvisoryCauseAndPlatformInfo( + mamaTransport tport, + short *cause, + const void **platformInfo); + +/** + * This function will set the cause and platform info for the transport. + * + * @param[in] transport The transport. + * @param[in] cause The cause. + * @param[in] platformInfo Bridge specific info. + * + */ +MAMAExpDLL +extern void +mamaTransportImpl_setAdvisoryCauseAndPlatformInfo( + mamaTransport transport, + short cause, + const void *platformInfo); + #endif /* TransportImplH__ */ -- 1.7.5.4
|
|
[PATCH] Use Transport Properties for FT Configuration
Michael Schonberg <mschonberg@...>
From: Mike Schonberg <mschonberg@...>
Currently, the FT setup code uses the hard-coded transport name, "ft", to read properties from mama.properties despite the fact that the caller supplies a mamaTransport reference. This change uses the supplied transport's name to lookup FT configuration properties. Signed-off-by: John Gray <jgray@...> --- mama/c_cpp/src/c/ft.c | 86 ++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 71 insertions(+), 15 deletions(-) diff --git a/mama/c_cpp/src/c/ft.c b/mama/c_cpp/src/c/ft.c index 2066b0c..efbc16d 100644 --- a/mama/c_cpp/src/c/ft.c +++ b/mama/c_cpp/src/c/ft.c @@ -58,6 +58,8 @@ #define FT_FIELD_IPADDRESS "MamaIPAddress" #define FT_FIELD_IPADDRESS_FID 206 +#define FT_MAX_PROPERTY_NAME_LENGTH 1024 + mama_status multicastFt_setup ( mamaFtMember member, @@ -105,6 +107,10 @@ static void bridgeFt_sendHeartbeat (mamaFtMember member); static int multicastFt_receiveHeartbeat(void* member); static int bridgeFt_receiveHeartbeat(void* member); +static const char* +multicastFt_getProperty(char *buffer, const char *propertyName, const char + *transportName); + static int foundheartbeat=0; /***************************************** @@ -878,6 +884,32 @@ struct in_addr resolve_ip (const char * arg) /**************************************************************************** * Multicast FT specific ******************************************************************************/ + +const char *multicastFt_getProperty(char *buffer, const char *propertyName, const char *transportName) +{ + /* Returns. */ + const char *ret = NULL; + + /* Format the full property name. */ + int numberWritten = snprintf(buffer, (FT_MAX_PROPERTY_NAME_LENGTH - 1), propertyName, transportName); + + /* If too many characters are written the log an error. */ + if((FT_MAX_PROPERTY_NAME_LENGTH - 1) < numberWritten) + { + mama_log(MAMA_LOG_LEVEL_ERROR, "%s Property name too long. Length [%d]," + " Max Length [%d].", transportName, strlen(transportName), + (FT_MAX_PROPERTY_NAME_LENGTH - 1)); + } + + else + { + /* Otherwise get the property. */ + ret = mama_getProperty(buffer); + } + + return ret; +} + mama_status multicastFt_setup ( mamaFtMember member, @@ -904,46 +936,70 @@ multicastFt_setup ( const char* ftNetwork = NULL; const char* ftTtl = NULL; const char* iorecvstr = NULL; + const char* transportName = NULL; + mama_status status = MAMA_STATUS_OK; struct in_addr iface; struct in_addr cFtIfAddr; + /* This buffer is used for formatting property names. */ + char propertyName[FT_MAX_PROPERTY_NAME_LENGTH] = ""; + mamaFtMemberImpl* impl = (mamaFtMemberImpl*) member; - if (!impl || !groupName) + if (!impl || !groupName || !transport) return MAMA_STATUS_INVALID_ARG; - ftInterface = mama_getProperty ("mama.multicast.transport.ft.interface"); - if (ftInterface == NULL) + /* Get the transport name. */ + status = mamaTransport_getName(transport, &transportName); + if((MAMA_STATUS_OK != status) || (NULL == transportName) || ('\0' == + transportName[0])) { - ftInterface = mama_getProperty ("mama.native.transport.ft.interface"); + mama_log (MAMA_LOG_LEVEL_ERROR, "MAMA multicast FT: the transport name " + "is invalid"); + return MAMA_STATUS_INVALID_ARG; + } + + ftInterface = multicastFt_getProperty(propertyName, + "mama.multicast.transport.%s.interface", transportName); if (ftInterface == NULL) + { + ftInterface = multicastFt_getProperty(propertyName, + "mama.native.transport.%s.interface", transportName); + if (ftInterface == NULL) ftInterface = ""; } - ftNetwork = mama_getProperty ("mama.multicast.transport.ft.network"); + ftNetwork = multicastFt_getProperty (propertyName, + "mama.multicast.transport.%s.network", transportName); if (ftNetwork == NULL) { - ftNetwork = mama_getProperty ("mama.native.transport.ft.network"); - if (ftNetwork == NULL) - ftNetwork = FT_NETWORK; + ftNetwork = multicastFt_getProperty (propertyName, + "mama.native.transport.%s.network", transportName); + if (ftNetwork == NULL) + ftNetwork = FT_NETWORK; } - ftService = mama_getProperty ("mama.multicast.transport.ft.service"); + ftService = multicastFt_getProperty (propertyName, + "mama.multicast.transport.%s.service", transportName); if (ftService == NULL) { - ftService = mama_getProperty ("mama.native.transport.ft.service"); + ftService = multicastFt_getProperty (propertyName, + "mama.native.transport.%s.service", transportName); if (ftService != NULL) - service = atol (ftService); + service = atol (ftService); } - ftTtl = mama_getProperty ("mama.multicast.transport.ft.ttl"); + ftTtl = multicastFt_getProperty (propertyName, + "mama.multicast.transport.%s.ttl", transportName); if (ftTtl == NULL) { - ftTtl = mama_getProperty ("mama.native.transport.ft.ttl"); + ftTtl = multicastFt_getProperty (propertyName, + "mama.native.transport.%s.ttl", transportName); if (ftTtl != NULL) - ttl = atol (ftTtl); + ttl = atol (ftTtl); } - iorecvstr = mama_getProperty ("mama.multicast.transport.ft.iowindow"); + iorecvstr = multicastFt_getProperty (propertyName, + "mama.multicast.transport.%s.iowindow", transportName); if (iorecvstr != NULL) { iorecv=atoi (iorecvstr); -- 1.7.5.4
|
|
[PATCH] Initialize Callbacks structs to 0 for mamasymbolist subscriber
Michael Schonberg <mschonberg@...>
From: Mike Schonberg <mschonberg@...>
This avoids a potentional sgmentation fault in the event that an uninitialized callback gets invoked. Signed-off-by: John Gray <jgray@...> --- .../src/examples/c/mamasymbollistsubscriberc.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/mama/c_cpp/src/examples/c/mamasymbollistsubscriberc.c b/mama/c_cpp/src/examples/c/mamasymbollistsubscriberc.c index 29a2eb7..0160df7 100644 --- a/mama/c_cpp/src/examples/c/mamasymbollistsubscriberc.c +++ b/mama/c_cpp/src/examples/c/mamasymbollistsubscriberc.c @@ -151,6 +151,7 @@ int main (int argc, const char **argv) mama_status status; mamaMsgCallbacks symbolListCallbacks; mamaSubscription symbolListSubscription; + memset(&symbolListCallbacks, 0, sizeof(symbolListCallbacks)); gSymbolList = (const char**) calloc (MAX_SUBSCRIPTIONS, sizeof (char*)); gSubscriptionList = (mamaSubscription*)calloc (MAX_SUBSCRIPTIONS, @@ -463,6 +464,7 @@ static void subscribeToSymbols (void) mama_status status = MAMA_STATUS_OK; size_t i; mamaMsgCallbacks callbacks; + memset(&callbacks, 0, sizeof(callbacks)); callbacks.onCreate = subscriptionOnCreate; callbacks.onError = subscriptionOnError; -- 1.7.5.4
|
|
[PATCH] Only invoke onQuality callbck for MAMA_MSG_TYPE_MISC
Michael Schonberg <mschonberg@...>
From: Mike Schonberg <mschonberg@...>
When amessage arrives with a status of POSSIBLY_STALE, verify that the message type is MAMA_MSG_TYPE_MISC. This behavior is consistent with OpenMAMA market data publishers. Signed-off-by: Michael Schonberg <mschonberg@...> --- mama/c_cpp/src/c/listenermsgcallback.c | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-) diff --git a/mama/c_cpp/src/c/listenermsgcallback.c b/mama/c_cpp/src/c/listenermsgcallback.c index 9e770a9..dca5474 100644 --- a/mama/c_cpp/src/c/listenermsgcallback.c +++ b/mama/c_cpp/src/c/listenermsgcallback.c @@ -306,6 +306,25 @@ listenerMsgCallback_processMsg( listenerMsgCallback callback, mamaMsg msg, handleNoSubscribers (impl, msg, ctx); return; } + + /* The possibly stale messages are sent by the MAMACACHE with a miscellanious type and should be translated + * into a quality event. + */ + case MAMA_MSG_STATUS_POSSIBLY_STALE: + { + /* Verify that the type is misc. */ + if(msgType == MAMA_MSG_TYPE_MISC) + { + /* Change the state to maybe stale and invoke the onquality callback. */ + mamaSubscription_setPossiblyStale(subscription); + break; + } + + /* Otherwise log the fact we have received an unknown message. */ + listenerMsgCallbackImpl_logUnknownStatus(ctx, status, subscription); + break; + } + case MAMA_MSG_STATUS_MISC: { if (msgType == MAMA_MSG_TYPE_REFRESH) -- 1.7.5.4
|
|
[PATCH] Added listenerMsgCallbackImpl_logUnknowStatus
Michael Schonberg <mschonberg@...>
From: Mike Schonberg <mschonberg@...>
This method refactors repeated logging statements and make the source easier to follow. Signed-off-by: Micheal Schonberg <mschonberg@...> --- mama/c_cpp/src/c/listenermsgcallback.c | 46 +++++++++++++++++++++++-------- 1 files changed, 34 insertions(+), 12 deletions(-) diff --git a/mama/c_cpp/src/c/listenermsgcallback.c b/mama/c_cpp/src/c/listenermsgcallback.c index cbc8224..9e770a9 100644 --- a/mama/c_cpp/src/c/listenermsgcallback.c +++ b/mama/c_cpp/src/c/listenermsgcallback.c @@ -64,6 +64,17 @@ listenerMsgCallbackImpl_invokeErrorCallback(listenerMsgCallback callback, subscription, const char *userSymbol); /** + * This function will write a log message if an unknown message status is detected. + * + * @param[in] ctx The subscription context. + * @param[in] status The message status. + * @param[in] subscription The subscription. + */ +static void +listenerMsgCallbackImpl_logUnknownStatus(SubjectContext *ctx, int status, + mamaSubscription subscription); + +/** * Main callback for MamaListener. This is the base strategy for * handling messages. */ @@ -303,21 +314,15 @@ listenerMsgCallback_processMsg( listenerMsgCallback callback, mamaMsg msg, * MISC status. */ break; } - /* else drop through to default... */ + + /* Otherwise log the fact we have received an unknown message. */ + listenerMsgCallbackImpl_logUnknownStatus(ctx, status, subscription); + break; } default: { - if ((gMamaLogLevel >= MAMA_LOG_LEVEL_FINE) || - (mamaSubscription_checkDebugLevel (subscription, - MAMA_LOG_LEVEL_FINE))) - { - const char* userSymbol = NULL; - mamaSubscription_getSymbol (subscription, &userSymbol); - mama_log (MAMA_LOG_LEVEL_FINE, - "%s%s%s%s Unexpected status: %s", - userSymbolFormatted, ctxSymbolFormatted, - mamaMsgStatus_stringForStatus( status ) ); - } + /* Log the fact we have received an unknown message. */ + listenerMsgCallbackImpl_logUnknownStatus(ctx, status, subscription); } } } @@ -572,3 +577,20 @@ void listenerMsgCallbackImpl_invokeErrorCallback(listenerMsgCallback callback, S userSymbol, closure); } + +void listenerMsgCallbackImpl_logUnknownStatus(SubjectContext *ctx, int status, + mamaSubscription subscription) +{ + /* Write the log at fine level. */ + if ((gMamaLogLevel >= MAMA_LOG_LEVEL_FINE) || + (mamaSubscription_checkDebugLevel (subscription, + MAMA_LOG_LEVEL_FINE))) + { + const char* userSymbol = NULL; + mamaSubscription_getSymbol (subscription, &userSymbol); + mama_log (MAMA_LOG_LEVEL_FINE, + "%s%s%s%s Unexpected status: %s", + userSymbolFormatted, ctxSymbolFormatted, + mamaMsgStatus_stringForStatus( status ) ); + } +} -- 1.7.5.4
|
|
[PATCH] Renamed listenerMsgCallback_invokeErrorCallback
Michael Schonberg <mschonberg@...>
From: Mike Schonberg <mschonberg@...>
Renamed listenerMsgCallbackImpl_invokeErrorCallback to listenerMsgCallbackImpl_invokeErrorCallback because it is an internal method. The method is also static and moved to the end of the file Signed-off-by: John Gray <jgray@...> --- mama/c_cpp/src/c/listenermsgcallback.c | 85 +++++++++++++++++++------------ 1 files changed, 52 insertions(+), 33 deletions(-) diff --git a/mama/c_cpp/src/c/listenermsgcallback.c b/mama/c_cpp/src/c/listenermsgcallback.c index 4ff9ea4..cbc8224 100644 --- a/mama/c_cpp/src/c/listenermsgcallback.c +++ b/mama/c_cpp/src/c/listenermsgcallback.c @@ -45,8 +45,23 @@ extern int gGenerateTransportStats; extern int gGenerateGlobalStats; extern int gGenerateQueueStats; -/* Function prototypes. */ -void listenerMsgCallback_invokeErrorCallback(listenerMsgCallback callback, SubjectContext *ctx, mama_status mamaStatus, mamaSubscription subscription, const char *userSymbol); +/* *************************************************** */ +/* Private Function Prototypes. */ +/* *************************************************** */ + +/** + * This function will invoke the subscription's onError callback passing in a particular error code. + * + * @param[in] callback The impl. + * @param[in] ctx The subscription context. + * @param[in] mamaStatus The status that will be passed to the error callback. + * @param[in] subscription The subscription. + * @param[in] userSymbol The symbol. + */ +static void +listenerMsgCallbackImpl_invokeErrorCallback(listenerMsgCallback callback, + SubjectContext *ctx, mama_status mamaStatus, mamaSubscription + subscription, const char *userSymbol); /** * Main callback for MamaListener. This is the base strategy for @@ -197,30 +212,6 @@ static void processPointToPointMessage (msgCallback* callback, * may have been destroyed in the callback! */ } -/* Description : This function will invoke the subscription's onError callback passing in a particular error code. - */ -void listenerMsgCallback_invokeErrorCallback(listenerMsgCallback callback, SubjectContext *ctx, mama_status mamaStatus, mamaSubscription subscription, const char *userSymbol) -{ - /* Local variables. */ - void *closure = NULL; - - /* Get the callback object from the subscription. */ - mamaMsgCallbacks *cbs = mamaSubscription_getUserCallbacks (subscription); - - /* Wait for a response. */ - mamaSubscription_stopWaitForResponse(subscription, ctx); - - /* Get the closure from the subscription. */ - mamaSubscription_getClosure (subscription, &closure); - - mama_setLastError (MAMA_ERROR_DEFAULT); - cbs->onError (subscription, - mamaStatus, - NULL, - userSymbol, - closure); -} - static int isInitialMessageOrRecap (msgCallback *callback, int msgType) { return msgType == MAMA_MSG_TYPE_INITIAL || @@ -287,17 +278,17 @@ listenerMsgCallback_processMsg( listenerMsgCallback callback, mamaMsg msg, { switch (status) { - case MAMA_MSG_STATUS_NOT_PERMISSIONED: - listenerMsgCallback_invokeErrorCallback(callback, ctx, MAMA_STATUS_NOT_PERMISSIONED, subscription, userSymbol); - return; + case MAMA_MSG_STATUS_NOT_PERMISSIONED: + listenerMsgCallbackImpl_invokeErrorCallback(callback, ctx, MAMA_STATUS_NOT_PERMISSIONED, subscription, userSymbol); + return; case MAMA_MSG_STATUS_BAD_SYMBOL: - listenerMsgCallback_invokeErrorCallback(callback, ctx, MAMA_STATUS_BAD_SYMBOL, subscription, userSymbol); - return; + listenerMsgCallbackImpl_invokeErrorCallback(callback, ctx, MAMA_STATUS_BAD_SYMBOL, subscription, userSymbol); + return; case MAMA_MSG_STATUS_NOT_FOUND: - listenerMsgCallback_invokeErrorCallback(callback, ctx, MAMA_STATUS_NOT_FOUND, subscription, userSymbol); - return; + listenerMsgCallbackImpl_invokeErrorCallback(callback, ctx, MAMA_STATUS_NOT_FOUND, subscription, userSymbol); + return; case MAMA_MSG_STATUS_NO_SUBSCRIBERS: { @@ -553,3 +544,31 @@ checkEntitlement( msgCallback *callback, mamaMsg msg, SubjectContext* ctx ) return 1; #endif /* WITH_ENTITLEMENTS */ } + +/* *************************************************** */ +/* Private Functions. */ +/* *************************************************** */ + +/* Description: This function will invoke the subscription's onError callback passing in a particular error code. + */ +void listenerMsgCallbackImpl_invokeErrorCallback(listenerMsgCallback callback, SubjectContext *ctx, mama_status mamaStatus, mamaSubscription subscription, const char *userSymbol) +{ + /* Local variables. */ + void *closure = NULL; + + /* Get the callback object from the subscription. */ + mamaMsgCallbacks *cbs = mamaSubscription_getUserCallbacks (subscription); + + /* Wait for a response. */ + mamaSubscription_stopWaitForResponse(subscription, ctx); + + /* Get the closure from the subscription. */ + mamaSubscription_getClosure (subscription, &closure); + + mama_setLastError (MAMA_ERROR_DEFAULT); + cbs->onError (subscription, + mamaStatus, + NULL, + userSymbol, + closure); +} -- 1.7.5.4
|
|
[PATCH] Added MAMA_STATUS_SUBSCRIPTION_GAP
Michael Schonberg <mschonberg@...>
From: Mike Schonberg <mschonberg@...>
Middleware bridges pass this status to the mamaSubscription onError callback when the middleware detects a gap: mamaSubscription_getUserCallbacks(sub)->onError(...) Middlewares that do not detect dropped messages will not use this status. Note that this callback is independent of the sequence number gap detection implemented by dqpublisher and dqstrategy. Signed-off-by: John Gray <jgray@...> --- mama/c_cpp/src/c/mama/status.h | 4 +++- mama/c_cpp/src/c/status.c | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/mama/c_cpp/src/c/mama/status.h b/mama/c_cpp/src/c/mama/status.h index bccb7e0..fa0c5f5 100644 --- a/mama/c_cpp/src/c/mama/status.h +++ b/mama/c_cpp/src/c/mama/status.h @@ -99,7 +99,9 @@ typedef enum /* Queue has open objects. */ MAMA_STATUS_QUEUE_OPEN_OBJECTS = 5002, /* The function isn't supported for this type of subscription. */ - MAMA_STATUS_SUBSCRIPTION_INVALID_TYPE = 5003 + MAMA_STATUS_SUBSCRIPTION_INVALID_TYPE = 5003, + /* The underlying transport saw a gap. */ + MAMA_STATUS_SUBSCRIPTION_GAP = 5004 #ifdef WITH_ENTITLEMENTS /* Out of memory */ diff --git a/mama/c_cpp/src/c/status.c b/mama/c_cpp/src/c/status.c index 1c394e3..7e7ff91 100644 --- a/mama/c_cpp/src/c/status.c +++ b/mama/c_cpp/src/c/status.c @@ -61,7 +61,8 @@ mamaStatus_stringForStatus (mama_status status) case MAMA_STATUS_SUBSCRIPTION_INVALID_STATE: return "MAMA_STATUS_SUBSCRIPTION_INVALID_STATE"; case MAMA_STATUS_QUEUE_OPEN_OBJECTS: return "MAMA_STATUS_QUEUE_OPEN_OBJECTS"; case MAMA_STATUS_SUBSCRIPTION_INVALID_TYPE: return "MAMA_STATUS_SUBSCRIPTION_INVALID_TYPE"; - + case MAMA_STATUS_SUBSCRIPTION_GAP: return "MAMA_STATUS_SUBSCRIPTION_GAP"; + #ifdef WITH_ENTITLEMENTS case MAMA_ENTITLE_STATUS_NOMEM : return "ENTITLE_STATUS_NOMEM"; case MAMA_ENTITLE_STATUS_BAD_PARAM : return "ENTITLE_STATUS_BAD_PARAM"; -- 1.7.5.4
|
|
[PATCH] Correctly log when the queue gets dereferenced too many times
Michael Schonberg <mschonberg@...>
From: Mike Schonberg <mschonberg@...>
The existing logic contained a race condition which would not consistently log the attempt to dereference a queue with a zero reference count. The interlocked variable also requires initialization. The methods are added as no-ops in common/wombat/wInterlocked.h for Linux, but they will have implementations for Windows. Signed-off-by: John Gray <jgray@...> --- common/c_cpp/src/c/wombat/wInterlocked.h | 23 +++++++++++++++++++++++ mama/c_cpp/src/c/queue.c | 6 +++++- mama/c_cpp/src/c/subscription.c | 3 +++ 3 files changed, 31 insertions(+), 1 deletions(-) diff --git a/common/c_cpp/src/c/wombat/wInterlocked.h b/common/c_cpp/src/c/wombat/wInterlocked.h index b75924e..c128804 100644 --- a/common/c_cpp/src/c/wombat/wInterlocked.h +++ b/common/c_cpp/src/c/wombat/wInterlocked.h @@ -69,6 +69,29 @@ adec32 (uint32_t* ptr) typedef uint32_t wInterlockedInt; /** + * This function will initialise a wInterlockedInt. + * + * @param[in] value Pointer to the item to be initialized. + * @return 0 on success. + */ + +WCOMMONINLINE int wInterlocked_initialize(wInterlockedInt *value) +{ + return 0; +} + +/** + * This function will destroy a wInterlockedInt. + * + * @param[in] value Pointer to the item to be destroyed. + * @return 0 on success. + */ +WCOMMONINLINE int wInterlocked_destroy(wInterlockedInt *value) +{ + return 0; +} + +/** * This function will atomically decrement a 32-bit integer value. * * @param[in] value Pointer to the value to be decremented. diff --git a/mama/c_cpp/src/c/queue.c b/mama/c_cpp/src/c/queue.c index 72e9892..7190819 100644 --- a/mama/c_cpp/src/c/queue.c +++ b/mama/c_cpp/src/c/queue.c @@ -198,6 +198,7 @@ mamaQueue_create (mamaQueue* queue, impl->mQueueMonitorClosure = NULL; /* Create the counter lock. */ + wInterlocked_initialize(&impl->mNumberOpenObjects); wInterlocked_set(0, &impl->mNumberOpenObjects); @@ -436,7 +437,7 @@ mamaQueue_decrementObjectCount(mamaQueueLockHandle *handle, int newCount = wInterlocked_decrement(&impl->mNumberOpenObjects); /* Write a log if something has gone wrong. */ - if(impl->mNumberOpenObjects < 0) + if(newCount < 0) { mama_log(MAMA_LOG_LEVEL_ERROR, "Queue 0x%p has been dereferenced too many times.", queue); } @@ -719,6 +720,9 @@ mamaQueue_destroy (mamaQueue queue) impl->mMamaQueueBridgeImpl = NULL; impl->mMsg = NULL; + /* Destroy the counter lock */ + wInterlocked_destroy(&impl->mNumberOpenObjects); + free (impl); mama_log (MAMA_LOG_LEVEL_FINEST, "Leaving mamaQueue_destroy for queue 0x%X.", queue); diff --git a/mama/c_cpp/src/c/subscription.c b/mama/c_cpp/src/c/subscription.c index d6d0c00..6c73978 100644 --- a/mama/c_cpp/src/c/subscription.c +++ b/mama/c_cpp/src/c/subscription.c @@ -1831,6 +1831,9 @@ void mamaSubscriptionImpl_deallocate(mamaSubscriptionImpl *impl) /* Destroy the mutex. */ wlock_destroy(impl->mCreateDestroyLock); + /* Destroy the state. */ + wInterlocked_destroy(&impl->mState); + /* Free the subscription impl. */ free(impl); } -- 1.7.5.4
|
|