comparison src/http/ngx_http_file_cache.c @ 5726:25ade23cf281

Core: added ngx_slab_calloc() and ngx_slab_calloc_locked(). These functions return zeroed memory, analogous to ngx_pcalloc().
author Ruslan Ermilov <ru@nginx.com>
date Wed, 04 Jun 2014 15:09:19 +0400
parents 5748ce74c1cc
children 2fe1967f8854
comparison
equal deleted inserted replaced
5725:eadf46f888e9 5726:25ade23cf281
676 rc = NGX_AGAIN; 676 rc = NGX_AGAIN;
677 677
678 goto done; 678 goto done;
679 } 679 }
680 680
681 fcn = ngx_slab_alloc_locked(cache->shpool, 681 fcn = ngx_slab_calloc_locked(cache->shpool,
682 sizeof(ngx_http_file_cache_node_t)); 682 sizeof(ngx_http_file_cache_node_t));
683 if (fcn == NULL) { 683 if (fcn == NULL) {
684 ngx_shmtx_unlock(&cache->shpool->mutex); 684 ngx_shmtx_unlock(&cache->shpool->mutex);
685 685
686 (void) ngx_http_file_cache_forced_expire(cache); 686 (void) ngx_http_file_cache_forced_expire(cache);
687 687
688 ngx_shmtx_lock(&cache->shpool->mutex); 688 ngx_shmtx_lock(&cache->shpool->mutex);
689 689
690 fcn = ngx_slab_alloc_locked(cache->shpool, 690 fcn = ngx_slab_calloc_locked(cache->shpool,
691 sizeof(ngx_http_file_cache_node_t)); 691 sizeof(ngx_http_file_cache_node_t));
692 if (fcn == NULL) { 692 if (fcn == NULL) {
693 rc = NGX_ERROR; 693 rc = NGX_ERROR;
694 goto failed; 694 goto failed;
695 } 695 }
696 } 696 }
702 702
703 ngx_rbtree_insert(&cache->sh->rbtree, &fcn->node); 703 ngx_rbtree_insert(&cache->sh->rbtree, &fcn->node);
704 704
705 fcn->uses = 1; 705 fcn->uses = 1;
706 fcn->count = 1; 706 fcn->count = 1;
707 fcn->updating = 0;
708 fcn->deleting = 0;
709 707
710 renew: 708 renew:
711 709
712 rc = NGX_DECLINED; 710 rc = NGX_DECLINED;
713 711
1616 1614
1617 fcn = ngx_http_file_cache_lookup(cache, c->key); 1615 fcn = ngx_http_file_cache_lookup(cache, c->key);
1618 1616
1619 if (fcn == NULL) { 1617 if (fcn == NULL) {
1620 1618
1621 fcn = ngx_slab_alloc_locked(cache->shpool, 1619 fcn = ngx_slab_calloc_locked(cache->shpool,
1622 sizeof(ngx_http_file_cache_node_t)); 1620 sizeof(ngx_http_file_cache_node_t));
1623 if (fcn == NULL) { 1621 if (fcn == NULL) {
1624 ngx_shmtx_unlock(&cache->shpool->mutex); 1622 ngx_shmtx_unlock(&cache->shpool->mutex);
1625 return NGX_ERROR; 1623 return NGX_ERROR;
1626 } 1624 }
1627 1625
1631 NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t)); 1629 NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t));
1632 1630
1633 ngx_rbtree_insert(&cache->sh->rbtree, &fcn->node); 1631 ngx_rbtree_insert(&cache->sh->rbtree, &fcn->node);
1634 1632
1635 fcn->uses = 1; 1633 fcn->uses = 1;
1636 fcn->count = 0;
1637 fcn->valid_msec = 0;
1638 fcn->error = 0;
1639 fcn->exists = 1; 1634 fcn->exists = 1;
1640 fcn->updating = 0;
1641 fcn->deleting = 0;
1642 fcn->uniq = 0;
1643 fcn->valid_sec = 0;
1644 fcn->body_start = 0;
1645 fcn->fs_size = c->fs_size; 1635 fcn->fs_size = c->fs_size;
1646 1636
1647 cache->sh->size += c->fs_size; 1637 cache->sh->size += c->fs_size;
1648 1638
1649 } else { 1639 } else {