ngx_int_t ngx_mutex_trylock(ngx_mutex_t *m) { int err; if (!ngx_threaded) { return NGX_OK; } ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "try lock mutex %p", m); err = pthread_mutex_trylock(&m->mutex); if (err == NGX_EBUSY) { return NGX_AGAIN; } if (err != 0) { ngx_log_error(NGX_LOG_ALERT, m->log, err, "pthread_mutex_trylock(%p) failed", m); ngx_abort(); } ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "mutex %p is locked", m); return NGX_OK; }
void ngx_debug_point(void) { ngx_core_conf_t *ccf; ccf = (ngx_core_conf_t *) ngx_get_conf(ngx_cycle->conf_ctx, ngx_core_module); switch (ccf->debug_points) { case NGX_DEBUG_POINTS_STOP: raise(SIGSTOP); break; case NGX_DEBUG_POINTS_ABORT: ngx_abort(); } }
void ngx_str_helper(ngx_str_t *str, ngx_str_op op) { static char backup; switch (op) { case ngx_str_push: backup = str->data[str->len]; str->data[str->len] = 0; break; case ngx_str_pop: str->data[str->len] = backup; break; default: ngx_abort(); } }
void ngx_debug_point(void) {//让自己停止,通知父进程 ngx_core_conf_t *ccf; ccf = (ngx_core_conf_t *) ngx_get_conf(ngx_cycle->conf_ctx, ngx_core_module); switch (ccf->debug_points) { case NGX_DEBUG_POINTS_STOP: raise(SIGSTOP); //SIGSTOP 停止(stopped)进程的执行. 注意它和terminate以及interrupt的区别: //该进程还未结束, 只是暂停执行. 本信号不能被阻塞, 处理或忽略. break; case NGX_DEBUG_POINTS_ABORT: ngx_abort(); } }
void ngx_mutex_lock(ngx_mutex_t *m) {//多线程用的互斥锁 int err; if (!ngx_threaded) { return; } ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "lock mutex %p", m); err = pthread_mutex_lock(&m->mutex); if (err != 0) { ngx_log_error(NGX_LOG_ALERT, m->log, err, "pthread_mutex_lock(%p) failed", m); ngx_abort(); } ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "mutex %p is locked", m); return; }