mama_status mamaQueue_destroyWait(mamaQueue queue) { /* Returns. */ mama_status ret = MAMA_STATUS_NULL_ARG; if(queue == NULL) { mama_log (MAMA_LOG_LEVEL_ERROR, "mamaQueue_destroy(): NULL queue."); } else { /* Attempt to destroy the queue. */ ret = mamaQueue_destroy(queue); /* If there are still open objects then keep trying. */ while(MAMA_STATUS_QUEUE_OPEN_OBJECTS == ret) { /* Dispatch messages for 10 ms. */ ret = mamaQueue_timedDispatch(queue, 10); if(MAMA_STATUS_OK == ret) { /* Attempt to destroy the queue again. */ ret = mamaQueue_destroy(queue); } } } return ret; }
mama_status mamaQueue_destroyTimedWait(mamaQueue queue, long timeout) { /* Returns. */ mama_status ret = MAMA_STATUS_NULL_ARG; if(queue == NULL) { mama_log (MAMA_LOG_LEVEL_ERROR, "mamaQueue_destroy(): NULL queue."); } else { /* Timeout must be greater than 0. */ if(timeout > 0) { /* Initialise a time counter. */ long currentTime = 0; /* Attempt to destroy the queue. */ ret = mamaQueue_destroy(queue); /* If there are still open objects then keep trying until the time runs out. */ while((MAMA_STATUS_QUEUE_OPEN_OBJECTS == ret) && (currentTime < timeout)) { /* Dispatch messages for 10 ms. */ ret = mamaQueue_timedDispatch(queue, 10); /* Should this not react to MAMA_STATUS_TIMEOUT too? */ if(MAMA_STATUS_OK == ret) { /* Add 10ms to the count. */ currentTime += 10; /* Attempt to destroy the queue again. */ ret = mamaQueue_destroy(queue); } } /* If the time has run out then return a specific error code. */ if((MAMA_STATUS_OK != ret) && (currentTime >= timeout)) { mama_log (MAMA_LOG_LEVEL_FINEST, "mamaQueue_destroy(): timed out destroying queue."); ret = MAMA_STATUS_OK; } } } return ret; }