Ubuntu 下 nginx-1.24.0 源码分析 - ngx_cycle_modules-CSDN博客
定义在 src/core/ngx_module.c
ngx_int_t
ngx_cycle_modules(ngx_cycle_t *cycle)
{/** create a list of modules to be used for this cycle,* copy static modules to it*/cycle->modules = ngx_pcalloc(cycle->pool, (ngx_max_module + 1)* sizeof(ngx_module_t *));if (cycle->modules == NULL) {return NGX_ERROR;}ngx_memcpy(cycle->modules, ngx_modules,ngx_modules_n * sizeof(ngx_module_t *));cycle->modules_n = ngx_modules_n;return NGX_OK;
}
cycle->modules = ngx_pcalloc(cycle->pool, (ngx_max_module + 1)* sizeof(ngx_module_t *));if (cycle->modules == NULL) {return NGX_ERROR;}
在 cycle 的内存池中分配内存,存储模块指针数组
ngx_max_module + 1:ngx_max_module 是最大模块数,+1 用于预留终止标记( NULL)
ngx_memcpy(cycle->modules, ngx_modules,ngx_modules_n * sizeof(ngx_module_t *));
将全局模块数组 ngx_modules 拷贝到 cycle->modules
cycle->modules_n = ngx_modules_n;
将全局模块数量
ngx_modules_n
赋值给cycle->modules_n
return NGX_OK;
返回 NGX_OK,代表 成功