added zap_assert_return macro and replaced old use of zap_assert

git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@911 a93c3328-9c30-0410-af19-c9cd2b2d52af
This commit is contained in:
Moises Silva 2009-11-27 18:57:35 +00:00
parent 2f09453095
commit ecf3294a88
5 changed files with 43 additions and 32 deletions

View File

@ -263,7 +263,7 @@
#define zap_set_state_locked(obj, s) if ( obj->state == s ) { \ #define zap_set_state_locked(obj, s) if ( obj->state == s ) { \
zap_log(ZAP_LOG_WARNING, "Why bother changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(obj->state), zap_channel_state2str(s)); \ zap_log(ZAP_LOG_WARNING, "Why bother changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(obj->state), zap_channel_state2str(s)); \
} else if (zap_test_flag(obj, ZAP_CHANNEL_READY)) { \ } else if (zap_test_flag(obj, ZAP_CHANNEL_READY)) { \
int st = obj->state; \ zap_channel_state_t st = obj->state; \
zap_channel_set_state(obj, s, 1); \ zap_channel_set_state(obj, s, 1); \
if (obj->state == s) zap_log(ZAP_LOG_DEBUG, "Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); \ if (obj->state == s) zap_log(ZAP_LOG_DEBUG, "Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); \
else zap_log(ZAP_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); \ else zap_log(ZAP_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); \
@ -770,10 +770,20 @@ ZIO_CODEC_FUNCTION(zio_alaw2ulaw);
#endif #endif
/*! /*!
\brief Allocate uninitialized memory \brief Assert condition
\command chunksize the chunk size
*/ */
#define zap_assert(assertion, retval, msg) \ #define zap_assert(assertion, msg) \
if (!(assertion)) { \
zap_log(ZAP_LOG_CRIT, msg); \
if (g_zap_crash_policy & ZAP_CRASH_ON_ASSERT) { \
abort(); \
} \
}
/*!
\brief Assert condition and return
*/
#define zap_assert_return(assertion, retval, msg) \
if (!(assertion)) { \ if (!(assertion)) { \
zap_log(ZAP_LOG_CRIT, msg); \ zap_log(ZAP_LOG_CRIT, msg); \
if (g_zap_crash_policy & ZAP_CRASH_ON_ASSERT) { \ if (g_zap_crash_policy & ZAP_CRASH_ON_ASSERT) { \

View File

@ -382,7 +382,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request)
if (--boost_request_timeout <= 0) { if (--boost_request_timeout <= 0) {
status = ZAP_FAIL; status = ZAP_FAIL;
*zchan = NULL; *zchan = NULL;
zap_log(ZAP_LOG_CRIT, "Timed out waiting for boost channel request response\n"); zap_log(ZAP_LOG_CRIT, "Timed out waiting for boost channel request response, current status: BST_WAITING\n");
goto done; goto done;
} }
} }
@ -394,12 +394,13 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request)
zap_log(ZAP_LOG_DEBUG, "Channel state changed to PROGRESS [Csid:%d]\n", r); zap_log(ZAP_LOG_DEBUG, "Channel state changed to PROGRESS [Csid:%d]\n", r);
} }
sanity = 5000; boost_request_timeout = 5000;
while(zap_running() && OUTBOUND_REQUESTS[r].status == BST_ACK) { while(zap_running() && OUTBOUND_REQUESTS[r].status == BST_ACK) {
zap_sleep(1); zap_sleep(1);
if (--sanity <= 0) { if (--boost_request_timeout <= 0) {
status = ZAP_FAIL; status = ZAP_FAIL;
*zchan = NULL; *zchan = NULL;
zap_log(ZAP_LOG_CRIT, "Timed out waiting for boost channel request response, current status: BST_ACK\n");
goto done; goto done;
} }
//printf("WTF %d\n", sanity); //printf("WTF %d\n", sanity);
@ -1654,7 +1655,7 @@ static BOOST_WRITE_MSG_FUNCTION(zap_boost_write_msg)
zap_sangoma_boost_data_t *sangoma_boost_data = NULL; zap_sangoma_boost_data_t *sangoma_boost_data = NULL;
sangomabc_queue_element_t *element = NULL; sangomabc_queue_element_t *element = NULL;
zap_assert(msg != NULL, ZAP_FAIL, "Boost message to write was null"); zap_assert_return(msg != NULL, ZAP_FAIL, "Boost message to write was null");
if (!span) { if (!span) {
shortmsg = msg; shortmsg = msg;

View File

@ -185,7 +185,7 @@ static __inline__ void *zap_std_malloc(void *pool, zap_size_t size)
{ {
void *ptr = malloc(size); void *ptr = malloc(size);
pool = NULL; /* fix warning */ pool = NULL; /* fix warning */
zap_assert(ptr != NULL, NULL, "Out of memory"); zap_assert_return(ptr != NULL, NULL, "Out of memory");
return ptr; return ptr;
} }
@ -193,14 +193,14 @@ static __inline__ void *zap_std_calloc(void *pool, zap_size_t elements, zap_size
{ {
void *ptr = calloc(elements, size); void *ptr = calloc(elements, size);
pool = NULL; pool = NULL;
zap_assert(ptr != NULL, NULL, "Out of memory"); zap_assert_return(ptr != NULL, NULL, "Out of memory");
return ptr; return ptr;
} }
static __inline__ void zap_std_free(void *pool, void *ptr) static __inline__ void zap_std_free(void *pool, void *ptr)
{ {
pool = NULL; pool = NULL;
zap_assert(ptr != NULL, , "Attempted to free null pointer"); zap_assert_return(ptr != NULL, , "Attempted to free null pointer");
free(ptr); free(ptr);
} }
@ -1263,8 +1263,8 @@ OZ_DECLARE(zap_status_t) zap_channel_outgoing_call(zap_channel_t *zchan)
OZ_DECLARE(zap_status_t) zap_channel_get_sig_status(zap_channel_t *zchan, zap_channel_sig_status_t *sigstatus) OZ_DECLARE(zap_status_t) zap_channel_get_sig_status(zap_channel_t *zchan, zap_channel_sig_status_t *sigstatus)
{ {
zap_assert(zchan != NULL, ZAP_FAIL, "Null channel\n"); zap_assert_return(zchan != NULL, ZAP_FAIL, "Null channel\n");
zap_assert(sigstatus != NULL, ZAP_FAIL, "Null sig status"); zap_assert_return(sigstatus != NULL, ZAP_FAIL, "Null sig status");
if (zchan->span->get_sig_status) { if (zchan->span->get_sig_status) {
return zchan->span->get_sig_status(zchan, sigstatus); return zchan->span->get_sig_status(zchan, sigstatus);
@ -2814,10 +2814,10 @@ OZ_DECLARE(zap_status_t) zap_configure_span_signaling(const char *type, zap_span
zap_module_t *mod = (zap_module_t *) hashtable_search(globals.module_hash, (void *)type); zap_module_t *mod = (zap_module_t *) hashtable_search(globals.module_hash, (void *)type);
zap_status_t status = ZAP_FAIL; zap_status_t status = ZAP_FAIL;
zap_assert(type != NULL, ZAP_FAIL, "No signaling type"); zap_assert_return(type != NULL, ZAP_FAIL, "No signaling type");
zap_assert(span != NULL, ZAP_FAIL, "No span"); zap_assert_return(span != NULL, ZAP_FAIL, "No span");
zap_assert(sig_cb != NULL, ZAP_FAIL, "No signaling callback"); zap_assert_return(sig_cb != NULL, ZAP_FAIL, "No signaling callback");
zap_assert(parameters != NULL, ZAP_FAIL, "No parameters"); zap_assert_return(parameters != NULL, ZAP_FAIL, "No parameters");
if (!mod) { if (!mod) {
zap_load_module_assume(type); zap_load_module_assume(type);

View File

@ -76,8 +76,8 @@ OZ_DECLARE(zap_status_t) zap_global_set_queue_handler(zap_queue_handler_t *handl
static zap_status_t zap_std_queue_create(zap_queue_t **outqueue, zap_size_t capacity) static zap_status_t zap_std_queue_create(zap_queue_t **outqueue, zap_size_t capacity)
{ {
zap_assert(outqueue, ZAP_FAIL, "Queue double pointer is null\n"); zap_assert_return(outqueue, ZAP_FAIL, "Queue double pointer is null\n");
zap_assert(capacity > 0, ZAP_FAIL, "Queue capacity is not bigger than 0\n"); zap_assert_return(capacity > 0, ZAP_FAIL, "Queue capacity is not bigger than 0\n");
*outqueue = NULL; *outqueue = NULL;
zap_queue_t *queue = zap_calloc(1, sizeof(*queue)); zap_queue_t *queue = zap_calloc(1, sizeof(*queue));
@ -120,7 +120,7 @@ static zap_status_t zap_std_queue_enqueue(zap_queue_t *queue, void *obj)
{ {
zap_status_t status = ZAP_FAIL; zap_status_t status = ZAP_FAIL;
zap_assert(queue != NULL, ZAP_FAIL, "Queue is null!"); zap_assert_return(queue != NULL, ZAP_FAIL, "Queue is null!");
zap_mutex_lock(queue->mutex); zap_mutex_lock(queue->mutex);
@ -152,7 +152,7 @@ static void *zap_std_queue_dequeue(zap_queue_t *queue)
{ {
void *obj = NULL; void *obj = NULL;
zap_assert(queue != NULL, NULL, "Queue is null!"); zap_assert_return(queue != NULL, NULL, "Queue is null!");
zap_mutex_lock(queue->mutex); zap_mutex_lock(queue->mutex);
@ -177,7 +177,7 @@ done:
static zap_status_t zap_std_queue_wait(zap_queue_t *queue, int ms) static zap_status_t zap_std_queue_wait(zap_queue_t *queue, int ms)
{ {
zap_status_t ret; zap_status_t ret;
zap_assert(queue != NULL, ZAP_FAIL, "Queue is null!"); zap_assert_return(queue != NULL, ZAP_FAIL, "Queue is null!");
zap_mutex_lock(queue->mutex); zap_mutex_lock(queue->mutex);
@ -199,8 +199,8 @@ static zap_status_t zap_std_queue_wait(zap_queue_t *queue, int ms)
static zap_status_t zap_std_queue_destroy(zap_queue_t **inqueue) static zap_status_t zap_std_queue_destroy(zap_queue_t **inqueue)
{ {
zap_queue_t *queue = NULL; zap_queue_t *queue = NULL;
zap_assert(inqueue != NULL, ZAP_FAIL, "Queue is null!"); zap_assert_return(inqueue != NULL, ZAP_FAIL, "Queue is null!");
zap_assert(*inqueue != NULL, ZAP_FAIL, "Queue is null!"); zap_assert_return(*inqueue != NULL, ZAP_FAIL, "Queue is null!");
queue = *inqueue; queue = *inqueue;
zap_condition_destroy(&queue->condition); zap_condition_destroy(&queue->condition);

View File

@ -242,8 +242,8 @@ OZ_DECLARE(zap_status_t) zap_condition_create(zap_condition_t **incondition, zap
{ {
zap_condition_t *condition = NULL; zap_condition_t *condition = NULL;
zap_assert(incondition != NULL, ZAP_FAIL, "Condition double pointer is null!\n"); zap_assert_return(incondition != NULL, ZAP_FAIL, "Condition double pointer is null!\n");
zap_assert(mutex != NULL, ZAP_FAIL, "Mutex for condition must not be null!\n"); zap_assert_return(mutex != NULL, ZAP_FAIL, "Mutex for condition must not be null!\n");
condition = zap_calloc(1, sizeof(*condition)); condition = zap_calloc(1, sizeof(*condition));
if (!condition) { if (!condition) {
@ -277,7 +277,7 @@ OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms)
#ifdef WIN32 #ifdef WIN32
DWORD res = 0; DWORD res = 0;
#endif #endif
zap_assert(condition != NULL, ZAP_FAIL, "Condition is null!\n"); zap_assert_return(condition != NULL, ZAP_FAIL, "Condition is null!\n");
#ifdef WIN32 #ifdef WIN32
res = WaitForSingleObject(condition->condition, ms > 0 ? ms : INFINITE); res = WaitForSingleObject(condition->condition, ms > 0 ? ms : INFINITE);
switch (res) { switch (res) {
@ -311,7 +311,7 @@ OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms)
OZ_DECLARE(zap_status_t) zap_condition_signal(zap_condition_t *condition) OZ_DECLARE(zap_status_t) zap_condition_signal(zap_condition_t *condition)
{ {
zap_assert(condition != NULL, ZAP_FAIL, "Condition is null!\n"); zap_assert_return(condition != NULL, ZAP_FAIL, "Condition is null!\n");
#ifdef WIN32 #ifdef WIN32
if (!SetEvent(condition->condition)) { if (!SetEvent(condition->condition)) {
return ZAP_FAIL; return ZAP_FAIL;
@ -329,7 +329,7 @@ OZ_DECLARE(zap_status_t) zap_condition_signal(zap_condition_t *condition)
OZ_DECLARE(zap_status_t) zap_condition_destroy(zap_condition_t **incondition) OZ_DECLARE(zap_status_t) zap_condition_destroy(zap_condition_t **incondition)
{ {
zap_condition_t *condition = NULL; zap_condition_t *condition = NULL;
zap_assert(incondition != NULL, ZAP_FAIL, "Condition null when destroying!\n"); zap_assert_return(incondition != NULL, ZAP_FAIL, "Condition null when destroying!\n");
condition = *incondition; condition = *incondition;
#ifdef WIN32 #ifdef WIN32
CloseHandle(condition->condition); CloseHandle(condition->condition);