zoukankan      html  css  js  c++  java
  • ngx_os_init解析

     1 ngx_int_t
     2 ngx_os_init(ngx_log_t *log)
     3 {
     4     ngx_time_t  *tp;
     5     ngx_uint_t   n;
     6 #if (NGX_HAVE_LEVEL1_DCACHE_LINESIZE)
     7     long         size;
     8 #endif
     9 
    10 #if (NGX_HAVE_OS_SPECIFIC_INIT)
    11     // 初始化linux内核版本号
    12     if (ngx_os_specific_init(log) != NGX_OK) {
    13         return NGX_ERROR;
    14     }
    15 #endif
    16     // 初始化proctitle内存空间
    17     if (ngx_init_setproctitle(log) != NGX_OK) {
    18         return NGX_ERROR;
    19     }
    20 
    21     // 获取page size
    22     ngx_pagesize = getpagesize();
    23     // 获取cacheline size
    24     ngx_cacheline_size = NGX_CPU_CACHE_LINE;
    25 
    26     // 2 ^ ngx_pagesize_shift == ngx_page_size
    27     for (n = ngx_pagesize; n >>= 1; ngx_pagesize_shift++) { /* void */ }
    28 
    29 #if (NGX_HAVE_SC_NPROCESSORS_ONLN)
    30     if (ngx_ncpu == 0) {
    31         // 获取CPU核数
    32         ngx_ncpu = sysconf(_SC_NPROCESSORS_ONLN);
    33     }
    34 #endif
    35 
    36     if (ngx_ncpu < 1) {
    37         ngx_ncpu = 1;
    38     }
    39 
    40 #if (NGX_HAVE_LEVEL1_DCACHE_LINESIZE)
    41     //获取1-cache line size
    42     size = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
    43     if (size > 0) {
    44         ngx_cacheline_size = size;
    45     }
    46 #endif
    47 
    48     // 根据CPU info获取cacheline size
    49     ngx_cpuinfo();
    50 
    51     //获取打开最多文件数
    52     if (getrlimit(RLIMIT_NOFILE, &rlmt) == -1) {
    53         ngx_log_error(NGX_LOG_ALERT, log, errno,
    54                       "getrlimit(RLIMIT_NOFILE) failed");
    55         return NGX_ERROR;
    56     }
    57 
    58     ngx_max_sockets = (ngx_int_t) rlmt.rlim_cur;
    59 
    60 #if (NGX_HAVE_INHERITED_NONBLOCK || NGX_HAVE_ACCEPT4)
    61     ngx_inherited_nonblocking = 1;
    62 #else
    63     ngx_inherited_nonblocking = 0;
    64 #endif
    65 
    66     tp = ngx_timeofday();
    67     //初始化rand种子
    68     srandom(((unsigned) ngx_pid << 16) ^ tp->sec ^ tp->msec);
    69 
    70     return NGX_OK;
    71 }
  • 相关阅读:
    win10下python环境变量设置
    c++ primer第15章这几个例子中的构造函数形式不太理解
    ++与*
    C++符号优先级
    56-Remove Linked List Elements
    55. Binary Tree Preorder Traversal
    54. Flatten Binary Tree to Linked List
    野指针--内存泄漏--缓存区溢出--栈溢出
    数组指针和指针数组的区别
    53-Linked List Cycle II
  • 原文地址:https://www.cnblogs.com/HadesBlog/p/13741890.html
Copyright © 2011-2022 走看看