nginx 源码阅读 core

 

ngx_config.h

数据对齐

#define ngx_align(d, a)     (((d) + (a - 1)) & ~(a - 1))

ngx_core.h

#define ngx_abs(value) (((value) >= 0) ? (value) : - (value))

#define ngx_max(val1, val2) ((val1 < val2) ? (val2) : (val1))

#define ngx_min(val1, val2) ((val1 > val2) ? (val2) : (val1))

数据结构

ngx_array

typedef struct {
void *elts;
ngx_uint_t nelts;
size_t size;
ngx_uint_t nalloc;
ngx_pool_t *pool;
} ngx_array_t;

ngx_palloc.h

内存池


typedef struct ngx_pool_cleanup_s ngx_pool_cleanup_t;

struct ngx_pool_cleanup_s {
ngx_pool_cleanup_pt handler;
void *data;
ngx_pool_cleanup_t *next;
};


typedef struct ngx_pool_large_s ngx_pool_large_t;

struct ngx_pool_large_s {
ngx_pool_large_t *next;
void *alloc;
};


typedef struct {
u_char *last;
u_char *end;
ngx_pool_t *next;
ngx_uint_t failed;
} ngx_pool_data_t;


struct ngx_pool_s {
ngx_pool_data_t d;
size_t max;
ngx_pool_t *current;
ngx_chain_t *chain;
ngx_pool_large_t *large;
ngx_pool_cleanup_t *cleanup;
ngx_log_t *log;
};

 

posted on 2013-07-25 10:54  andyhe  阅读(268)  评论(0编辑  收藏  举报

导航