Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.13.12 ]​[ nginx-1.12.2 ]​

0001 
0002 /*
0003  * Copyright (C) Igor Sysoev
0004  * Copyright (C) Nginx, Inc.
0005  */
0006 
0007 
0008 #ifndef _NGX_PALLOC_H_INCLUDED_
0009 #define _NGX_PALLOC_H_INCLUDED_
0010 
0011 
0012 #include <ngx_config.h>
0013 #include <ngx_core.h>
0014 
0015 
0016 /*
0017  * NGX_MAX_ALLOC_FROM_POOL should be (ngx_pagesize - 1), i.e. 4095 on x86.
0018  * On Windows NT it decreases a number of locked pages in a kernel.
0019  */
0020 #define NGX_MAX_ALLOC_FROM_POOL  (ngx_pagesize - 1)
0021 
0022 #define NGX_DEFAULT_POOL_SIZE    (16 * 1024)
0023 
0024 #define NGX_POOL_ALIGNMENT       16
0025 #define NGX_MIN_POOL_SIZE                                                     \
0026     ngx_align((sizeof(ngx_pool_t) + 2 * sizeof(ngx_pool_large_t)),            \
0027               NGX_POOL_ALIGNMENT)
0028 
0029 
0030 typedef void (*ngx_pool_cleanup_pt)(void *data);
0031 
0032 typedef struct ngx_pool_cleanup_s  ngx_pool_cleanup_t;
0033 
0034 struct ngx_pool_cleanup_s {
0035     ngx_pool_cleanup_pt   handler;
0036     void                 *data;
0037     ngx_pool_cleanup_t   *next;
0038 };
0039 
0040 
0041 typedef struct ngx_pool_large_s  ngx_pool_large_t;
0042 
0043 struct ngx_pool_large_s {
0044     ngx_pool_large_t     *next;
0045     void                 *alloc;
0046 };
0047 
0048 
0049 typedef struct {
0050     u_char               *last;
0051     u_char               *end;
0052     ngx_pool_t           *next;
0053     ngx_uint_t            failed;
0054 } ngx_pool_data_t;
0055 
0056 
0057 struct ngx_pool_s {
0058     ngx_pool_data_t       d;
0059     size_t                max;
0060     ngx_pool_t           *current;
0061     ngx_chain_t          *chain;
0062     ngx_pool_large_t     *large;
0063     ngx_pool_cleanup_t   *cleanup;
0064     ngx_log_t            *log;
0065 };
0066 
0067 
0068 typedef struct {
0069     ngx_fd_t              fd;
0070     u_char               *name;
0071     ngx_log_t            *log;
0072 } ngx_pool_cleanup_file_t;
0073 
0074 
0075 void *ngx_alloc(size_t size, ngx_log_t *log);
0076 void *ngx_calloc(size_t size, ngx_log_t *log);
0077 
0078 ngx_pool_t *ngx_create_pool(size_t size, ngx_log_t *log);
0079 void ngx_destroy_pool(ngx_pool_t *pool);
0080 void ngx_reset_pool(ngx_pool_t *pool);
0081 
0082 void *ngx_palloc(ngx_pool_t *pool, size_t size);
0083 void *ngx_pnalloc(ngx_pool_t *pool, size_t size);
0084 void *ngx_pcalloc(ngx_pool_t *pool, size_t size);
0085 void *ngx_pmemalign(ngx_pool_t *pool, size_t size, size_t alignment);
0086 ngx_int_t ngx_pfree(ngx_pool_t *pool, void *p);
0087 
0088 
0089 ngx_pool_cleanup_t *ngx_pool_cleanup_add(ngx_pool_t *p, size_t size);
0090 void ngx_pool_run_cleanup_file(ngx_pool_t *p, ngx_fd_t fd);
0091 void ngx_pool_cleanup_file(void *data);
0092 void ngx_pool_delete_file(void *data);
0093 
0094 
0095 #endif /* _NGX_PALLOC_H_INCLUDED_ */