mirror of
https://github.com/nginx/nginx.git
synced 2025-06-10 11:38:36 +08:00
Core: added ngx_slab_calloc() and ngx_slab_calloc_locked().
These functions return zeroed memory, analogous to ngx_pcalloc().
This commit is contained in:
parent
d1ba20d0c9
commit
05d717b35d
@ -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
|
void
|
||||||
ngx_slab_free(ngx_slab_pool_t *pool, void *p)
|
ngx_slab_free(ngx_slab_pool_t *pool, void *p)
|
||||||
{
|
{
|
||||||
|
@ -50,6 +50,8 @@ typedef struct {
|
|||||||
void ngx_slab_init(ngx_slab_pool_t *pool);
|
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(ngx_slab_pool_t *pool, size_t size);
|
||||||
void *ngx_slab_alloc_locked(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(ngx_slab_pool_t *pool, void *p);
|
||||||
void ngx_slab_free_locked(ngx_slab_pool_t *pool, void *p);
|
void ngx_slab_free_locked(ngx_slab_pool_t *pool, void *p);
|
||||||
|
|
||||||
|
@ -678,7 +678,7 @@ ngx_http_file_cache_exists(ngx_http_file_cache_t *cache, ngx_http_cache_t *c)
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
fcn = ngx_slab_alloc_locked(cache->shpool,
|
fcn = ngx_slab_calloc_locked(cache->shpool,
|
||||||
sizeof(ngx_http_file_cache_node_t));
|
sizeof(ngx_http_file_cache_node_t));
|
||||||
if (fcn == NULL) {
|
if (fcn == NULL) {
|
||||||
ngx_shmtx_unlock(&cache->shpool->mutex);
|
ngx_shmtx_unlock(&cache->shpool->mutex);
|
||||||
@ -687,7 +687,7 @@ ngx_http_file_cache_exists(ngx_http_file_cache_t *cache, ngx_http_cache_t *c)
|
|||||||
|
|
||||||
ngx_shmtx_lock(&cache->shpool->mutex);
|
ngx_shmtx_lock(&cache->shpool->mutex);
|
||||||
|
|
||||||
fcn = ngx_slab_alloc_locked(cache->shpool,
|
fcn = ngx_slab_calloc_locked(cache->shpool,
|
||||||
sizeof(ngx_http_file_cache_node_t));
|
sizeof(ngx_http_file_cache_node_t));
|
||||||
if (fcn == NULL) {
|
if (fcn == NULL) {
|
||||||
rc = NGX_ERROR;
|
rc = NGX_ERROR;
|
||||||
@ -704,8 +704,6 @@ ngx_http_file_cache_exists(ngx_http_file_cache_t *cache, ngx_http_cache_t *c)
|
|||||||
|
|
||||||
fcn->uses = 1;
|
fcn->uses = 1;
|
||||||
fcn->count = 1;
|
fcn->count = 1;
|
||||||
fcn->updating = 0;
|
|
||||||
fcn->deleting = 0;
|
|
||||||
|
|
||||||
renew:
|
renew:
|
||||||
|
|
||||||
@ -1618,7 +1616,7 @@ ngx_http_file_cache_add(ngx_http_file_cache_t *cache, ngx_http_cache_t *c)
|
|||||||
|
|
||||||
if (fcn == NULL) {
|
if (fcn == NULL) {
|
||||||
|
|
||||||
fcn = ngx_slab_alloc_locked(cache->shpool,
|
fcn = ngx_slab_calloc_locked(cache->shpool,
|
||||||
sizeof(ngx_http_file_cache_node_t));
|
sizeof(ngx_http_file_cache_node_t));
|
||||||
if (fcn == NULL) {
|
if (fcn == NULL) {
|
||||||
ngx_shmtx_unlock(&cache->shpool->mutex);
|
ngx_shmtx_unlock(&cache->shpool->mutex);
|
||||||
@ -1633,15 +1631,7 @@ ngx_http_file_cache_add(ngx_http_file_cache_t *cache, ngx_http_cache_t *c)
|
|||||||
ngx_rbtree_insert(&cache->sh->rbtree, &fcn->node);
|
ngx_rbtree_insert(&cache->sh->rbtree, &fcn->node);
|
||||||
|
|
||||||
fcn->uses = 1;
|
fcn->uses = 1;
|
||||||
fcn->count = 0;
|
|
||||||
fcn->valid_msec = 0;
|
|
||||||
fcn->error = 0;
|
|
||||||
fcn->exists = 1;
|
fcn->exists = 1;
|
||||||
fcn->updating = 0;
|
|
||||||
fcn->deleting = 0;
|
|
||||||
fcn->uniq = 0;
|
|
||||||
fcn->valid_sec = 0;
|
|
||||||
fcn->body_start = 0;
|
|
||||||
fcn->fs_size = c->fs_size;
|
fcn->fs_size = c->fs_size;
|
||||||
|
|
||||||
cache->sh->size += c->fs_size;
|
cache->sh->size += c->fs_size;
|
||||||
|
Loading…
Reference in New Issue
Block a user