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,代表 成功
?