diff options
| author | Ruslan Ermilov <ru@nginx.com> | 2014-06-04 15:09:19 +0400 |
|---|---|---|
| committer | Ruslan Ermilov <ru@nginx.com> | 2014-06-04 15:09:19 +0400 |
| commit | 05d717b35d02c493533f6244a85b6c78a59f4272 (patch) | |
| tree | 0be8ef3eb996dc2cacb775005e1d7a734a809ae5 /src/core | |
| parent | d1ba20d0c971f4a76fef5ba8d39e757b9a7fa3af (diff) | |
| download | nginx-05d717b35d02c493533f6244a85b6c78a59f4272.tar.gz nginx-05d717b35d02c493533f6244a85b6c78a59f4272.tar.bz2 | |
Core: added ngx_slab_calloc() and ngx_slab_calloc_locked().
These functions return zeroed memory, analogous to ngx_pcalloc().
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/ngx_slab.c | 29 | ||||
| -rw-r--r-- | src/core/ngx_slab.h | 2 |
2 files changed, 31 insertions, 0 deletions
diff --git a/src/core/ngx_slab.c b/src/core/ngx_slab.c index be3e54084..24f2ff16a 100644 --- a/src/core/ngx_slab.c +++ b/src/core/ngx_slab.c @@ -398,6 +398,35 @@ done: } +void * +ngx_slab_calloc(ngx_slab_pool_t *pool, size_t size) +{ + void *p; + + ngx_shmtx_lock(&pool->mutex); + + p = ngx_slab_calloc_locked(pool, size); + + ngx_shmtx_unlock(&pool->mutex); + + return p; +} + + +void * +ngx_slab_calloc_locked(ngx_slab_pool_t *pool, size_t size) +{ + void *p; + + p = ngx_slab_alloc_locked(pool, size); + if (p) { + ngx_memzero(p, size); + } + + return p; +} + + void ngx_slab_free(ngx_slab_pool_t *pool, void *p) { diff --git a/src/core/ngx_slab.h b/src/core/ngx_slab.h index 1ee65d531..2922a80c7 100644 --- a/src/core/ngx_slab.h +++ b/src/core/ngx_slab.h @@ -50,6 +50,8 @@ typedef struct { void ngx_slab_init(ngx_slab_pool_t *pool); void *ngx_slab_alloc(ngx_slab_pool_t *pool, size_t size); void *ngx_slab_alloc_locked(ngx_slab_pool_t *pool, size_t size); +void *ngx_slab_calloc(ngx_slab_pool_t *pool, size_t size); +void *ngx_slab_calloc_locked(ngx_slab_pool_t *pool, size_t size); void ngx_slab_free(ngx_slab_pool_t *pool, void *p); void ngx_slab_free_locked(ngx_slab_pool_t *pool, void *p); |
