Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.15.11 ]​[ nginx-1.14.2 ]​

0001 
0002 /*
0003  * Copyright (C) Igor Sysoev
0004  * Copyright (C) Nginx, Inc.
0005  */
0006 
0007 
0008 #include <ngx_config.h>
0009 #include <ngx_core.h>
0010 
0011 
0012 ngx_uint_t  ngx_pagesize;
0013 ngx_uint_t  ngx_pagesize_shift;
0014 ngx_uint_t  ngx_cacheline_size;
0015 
0016 
0017 void *
0018 ngx_alloc(size_t size, ngx_log_t *log)
0019 {
0020     void  *p;
0021 
0022     p = malloc(size);
0023     if (p == NULL) {
0024         ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
0025                       "malloc(%uz) failed", size);
0026     }
0027 
0028     ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0, "malloc: %p:%uz", p, size);
0029 
0030     return p;
0031 }
0032 
0033 
0034 void *
0035 ngx_calloc(size_t size, ngx_log_t *log)
0036 {
0037     void  *p;
0038 
0039     p = ngx_alloc(size, log);
0040 
0041     if (p) {
0042         ngx_memzero(p, size);
0043     }
0044 
0045     return p;
0046 }
0047 
0048 
0049 #if (NGX_HAVE_POSIX_MEMALIGN)
0050 
0051 void *
0052 ngx_memalign(size_t alignment, size_t size, ngx_log_t *log)
0053 {
0054     void  *p;
0055     int    err;
0056 
0057     err = posix_memalign(&p, alignment, size);
0058 
0059     if (err) {
0060         ngx_log_error(NGX_LOG_EMERG, log, err,
0061                       "posix_memalign(%uz, %uz) failed", alignment, size);
0062         p = NULL;
0063     }
0064 
0065     ngx_log_debug3(NGX_LOG_DEBUG_ALLOC, log, 0,
0066                    "posix_memalign: %p:%uz @%uz", p, size, alignment);
0067 
0068     return p;
0069 }
0070 
0071 #elif (NGX_HAVE_MEMALIGN)
0072 
0073 void *
0074 ngx_memalign(size_t alignment, size_t size, ngx_log_t *log)
0075 {
0076     void  *p;
0077 
0078     p = memalign(alignment, size);
0079     if (p == NULL) {
0080         ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
0081                       "memalign(%uz, %uz) failed", alignment, size);
0082     }
0083 
0084     ngx_log_debug3(NGX_LOG_DEBUG_ALLOC, log, 0,
0085                    "memalign: %p:%uz @%uz", p, size, alignment);
0086 
0087     return p;
0088 }
0089 
0090 #endif