src/core/ngx_list.h - nginx-1.7.10

Data types defined

Functions defined

Macros defined

Source code


  1. /*
  2. * Copyright (C) Igor Sysoev
  3. * Copyright (C) Nginx, Inc.
  4. */


  5. #ifndef _NGX_LIST_H_INCLUDED_
  6. #define _NGX_LIST_H_INCLUDED_


  7. #include <ngx_config.h>
  8. #include <ngx_core.h>


  9. typedef struct ngx_list_part_s  ngx_list_part_t;

  10. struct ngx_list_part_s {
  11.     void             *elts;
  12.     ngx_uint_t        nelts;
  13.     ngx_list_part_t  *next;
  14. };


  15. typedef struct {
  16.     ngx_list_part_t  *last;
  17.     ngx_list_part_t   part;
  18.     size_t            size;
  19.     ngx_uint_t        nalloc;
  20.     ngx_pool_t       *pool;
  21. } ngx_list_t;


  22. ngx_list_t *ngx_list_create(ngx_pool_t *pool, ngx_uint_t n, size_t size);

  23. static ngx_inline ngx_int_t
  24. ngx_list_init(ngx_list_t *list, ngx_pool_t *pool, ngx_uint_t n, size_t size)
  25. {
  26.     list->part.elts = ngx_palloc(pool, n * size);
  27.     if (list->part.elts == NULL) {
  28.         return NGX_ERROR;
  29.     }

  30.     list->part.nelts = 0;
  31.     list->part.next = NULL;
  32.     list->last = &list->part;
  33.     list->size = size;
  34.     list->nalloc = n;
  35.     list->pool = pool;

  36.     return NGX_OK;
  37. }


  38. /*
  39. *
  40. *  the iteration through the list:
  41. *
  42. *  part = &list.part;
  43. *  data = part->elts;
  44. *
  45. *  for (i = 0 ;; i++) {
  46. *
  47. *      if (i >= part->nelts) {
  48. *          if (part->next == NULL) {
  49. *              break;
  50. *          }
  51. *
  52. *          part = part->next;
  53. *          data = part->elts;
  54. *          i = 0;
  55. *      }
  56. *
  57. *      ...  data[i] ...
  58. *
  59. *  }
  60. */


  61. void *ngx_list_push(ngx_list_t *list);


  62. #endif /* _NGX_LIST_H_INCLUDED_ */