mamaQueueLockHandle mamaQueue_incrementObjectCount(mamaQueue queue, void *owner) { /* Returns. */ mamaQueueLockHandle ret = NULL; /* Cast the queue to an impl. */ mamaQueueImpl *impl = (mamaQueueImpl *)queue; /* Increment the count. */ int newCount = wInterlocked_increment(&impl->mNumberOpenObjects); /* Check if lock tracking is turned on. */ if(1 == impl->mTrackObjectLocks) { /* Allocate a lock structure, this means that if the lock count isn't decremented there will * be a memory leak the stack for which will be picked up by any leak diagnostic tool. */ pMamaQueueLock lockStruct = (pMamaQueueLock)calloc(1, sizeof(mamaQueueLock)); if(NULL != lockStruct) { /* Write a log message at normal level. */ mama_log(MAMA_LOG_LEVEL_NORMAL, "mamaQueue_incrementObjectCount(): queue 0x%p, owner 0x%p, new count %d.", queue, owner, newCount); /* Save the owner pointer. */ lockStruct->m_owner = owner; /* This will be the return handle. */ ret = (mamaQueueLockHandle)lockStruct; } } return ret; }
mama_status mamaQueue_create_usingNative (mamaQueue* queue, mamaBridge bridgeImpl, void* nativeQueue) { mama_status status = MAMA_STATUS_OK; mamaBridgeImpl* bImpl = (mamaBridgeImpl*)bridgeImpl; mamaQueueImpl* impl = NULL; char queueName[32]; if (!bridgeImpl) { mama_log (MAMA_LOG_LEVEL_ERROR, "mamaQueue_create(): NULL bridge."); return MAMA_STATUS_NO_BRIDGE_IMPL; } if (!queue) { mama_log (MAMA_LOG_LEVEL_ERROR, "mamaQueue_create(): NULL queue" " address."); return MAMA_STATUS_NULL_ARG; } /* Generate a unique queue name */ snprintf (queueName, sizeof(queueName), "NO_NAME_%d", wInterlocked_increment(&gQueueNumber)); /*Create the queue structure*/ impl = (mamaQueueImpl*)calloc (1, sizeof (mamaQueueImpl)); if (!impl) return MAMA_STATUS_NOMEM; impl->mBridgeImpl = bImpl; impl->mMamaQueueBridgeImpl = NULL; impl->mDispatcher = NULL; impl->mQueueName = strdup (queueName); impl->mHighWatermark = 0; impl->mLowWatermark = 1; impl->mQueueMonitorCallbacks.onQueueHighWatermarkExceeded = NULL; impl->mQueueMonitorCallbacks.onQueueLowWatermark = NULL; impl->mQueueMonitorClosure = NULL; /* Create the counter lock. */ wInterlocked_set(0, &impl->mNumberOpenObjects); mamaQueue_createReuseableMsg(impl); /* Call the bridge impl specific queue create function*/ if (MAMA_STATUS_OK!=(status=impl->mBridgeImpl->bridgeMamaQueueCreateUsingNative (&(impl->mMamaQueueBridgeImpl), impl, nativeQueue))) { mama_log (MAMA_LOG_LEVEL_ERROR, "Could not create queue bridge."); mamaQueue_destroy ((mamaQueue)impl); return status; } *queue = (mamaQueue)impl; return MAMA_STATUS_OK; }
mama_status mamaQueue_create (mamaQueue* queue, mamaBridge bridgeImpl) { mama_status status = MAMA_STATUS_OK; mamaBridgeImpl* bImpl = (mamaBridgeImpl*)bridgeImpl; mamaQueueImpl* impl = NULL; char queueName[32]; if (!bridgeImpl) { mama_log (MAMA_LOG_LEVEL_ERROR, "mamaQueue_create(): NULL bridge."); return MAMA_STATUS_NO_BRIDGE_IMPL; } if (!queue) { mama_log (MAMA_LOG_LEVEL_ERROR, "mamaQueue_create(): NULL queue" " address."); return MAMA_STATUS_NULL_ARG; } /* Generate a unique queue name */ snprintf (queueName, sizeof(queueName), "NO_NAME_%d", wInterlocked_increment(&gQueueNumber)); /*Create the queue structure*/ impl = (mamaQueueImpl*)calloc (1, sizeof (mamaQueueImpl)); if (!impl) return MAMA_STATUS_NOMEM; impl->mBridgeImpl = bImpl; impl->mMamaQueueBridgeImpl = NULL; impl->mDispatcher = NULL; impl->mQueueName = strdup (queueName); impl->mHighWatermark = 0; impl->mLowWatermark = 1; impl->mQueueMonitorCallbacks.onQueueHighWatermarkExceeded = NULL; impl->mQueueMonitorCallbacks.onQueueLowWatermark = NULL; impl->mQueueMonitorClosure = NULL; /* Create the counter lock. */ wInterlocked_initialize(&impl->mNumberOpenObjects); wInterlocked_set(0, &impl->mNumberOpenObjects); wInterlocked_initialize(&impl->mIsDispatching); wInterlocked_set(0, &impl->mIsDispatching); /* Call the bridge impl specific queue create function*/ if (MAMA_STATUS_OK!=(status=impl->mBridgeImpl->bridgeMamaQueueCreate (&(impl->mMamaQueueBridgeImpl), impl))) { mama_log (MAMA_LOG_LEVEL_ERROR, "Could not create queue bridge."); mamaQueue_destroy ((mamaQueue)impl); return status; } /* Determine if object lock tracking is enabled. */ { const char *propValue = mama_getProperty(MAMAQUEUE_PROPERTY_OBJECT_LOCK_TRACKING); /* Only do this if it's set. */ if(NULL != propValue) { impl->mTrackObjectLocks = strtobool(propValue); } } *queue = (mamaQueue)impl; mamaQueue_enableStats((mamaQueue)impl); return MAMA_STATUS_OK; }