Made nxt_assert() statements to be compiled only with debug.

This commit is contained in:
Valentin Bartenev
2018-02-09 19:07:55 +03:00
parent fc496c19ac
commit 24d07cfdd2
3 changed files with 30 additions and 16 deletions

View File

@@ -122,6 +122,15 @@ nxt_log_debug(_log, ...) \
} while (0)
#define nxt_assert(c) \
do { \
if (nxt_slow_path(!(c))) { \
nxt_thread_log_alert("%s:%d assertion failed: %s", \
__FILE__, __LINE__, #c); \
nxt_abort(); \
} \
} while (0)
#else
#define nxt_debug(...)
@@ -129,6 +138,8 @@ nxt_log_debug(_log, ...) \
#define \
nxt_log_debug(...)
#define nxt_assert(c)
#endif
@@ -170,17 +181,4 @@ NXT_EXPORT extern nxt_log_t nxt_main_log;
NXT_EXPORT extern nxt_str_t nxt_log_levels[];
#define nxt_assert(c) \
do { \
if (nxt_fast_path(c)) { \
break; \
\
} else { \
nxt_thread_log_alert("%s:%d assertion failed: %s", \
__FILE__, __LINE__, #c ); \
nxt_abort(); \
} \
} while (0)
#endif /* _NXT_LOG_H_INCLUDED_ */

View File

@@ -527,14 +527,20 @@ nxt_port_mmap_tracking_cancel(nxt_task_t *task,
nxt_int_t
nxt_port_mmap_tracking_write(uint32_t *buf, nxt_port_mmap_tracking_t *t)
{
nxt_atomic_t *tracking;
nxt_port_mmap_handler_t *mmap_handler;
mmap_handler = t->mmap_handler;
#if (NXT_DEBUG)
{
nxt_atomic_t *tracking;
tracking = mmap_handler->hdr->tracking;
nxt_assert(t->tracking >= tracking);
nxt_assert(t->tracking < tracking + PORT_MMAP_CHUNK_COUNT);
}
#endif
buf[0] = mmap_handler->hdr->id;
buf[1] = t->tracking - mmap_handler->hdr->tracking;

View File

@@ -117,11 +117,15 @@ nxt_router_ra_inc_use(nxt_req_app_link_t *ra)
nxt_inline void
nxt_router_ra_dec_use(nxt_req_app_link_t *ra)
{
#if (NXT_DEBUG)
int c;
c = nxt_atomic_fetch_add(&ra->use_count, -1);
nxt_assert(c > 1);
#else
(void) nxt_atomic_fetch_add(&ra->use_count, -1);
#endif
}
static void nxt_router_ra_use(nxt_task_t *task, nxt_req_app_link_t *ra, int i);
@@ -3005,18 +3009,24 @@ nxt_router_app_quit(nxt_task_t *task, nxt_app_t *app)
static void
nxt_router_app_process_request(nxt_task_t *task, void *obj, void *data)
{
nxt_app_t *app;
nxt_req_app_link_t *ra;
app = obj;
ra = data;
#if (NXT_DEBUG)
{
nxt_app_t *app;
app = obj;
nxt_assert(app != NULL);
nxt_assert(ra != NULL);
nxt_assert(ra->app_port != NULL);
nxt_debug(task, "app '%V' %p process next stream #%uD",
&app->name, app, ra->stream);
}
#endif
nxt_router_app_prepare_request(task, ra);
}