src/core/ngx_slab.h - nginx source code

Data types defined

Macros defined

Source code


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


  5. #ifndef _NGX_SLAB_H_INCLUDED_
  6. #define _NGX_SLAB_H_INCLUDED_


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


  9. typedef struct ngx_slab_page_s  ngx_slab_page_t;

  10. struct ngx_slab_page_s {
  11.     uintptr_t         slab;
  12.     ngx_slab_page_t  *next;
  13.     uintptr_t         prev;
  14. };


  15. typedef struct {
  16.     ngx_uint_t        total;
  17.     ngx_uint_t        used;

  18.     ngx_uint_t        reqs;
  19.     ngx_uint_t        fails;
  20. } ngx_slab_stat_t;


  21. typedef struct {
  22.     ngx_shmtx_sh_t    lock;

  23.     size_t            min_size;
  24.     size_t            min_shift;

  25.     ngx_slab_page_t  *pages;
  26.     ngx_slab_page_t  *last;
  27.     ngx_slab_page_t   free;

  28.     ngx_slab_stat_t  *stats;
  29.     ngx_uint_t        pfree;

  30.     u_char           *start;
  31.     u_char           *end;

  32.     ngx_shmtx_t       mutex;

  33.     u_char           *log_ctx;
  34.     u_char            zero;

  35.     unsigned          log_nomem:1;

  36.     void             *data;
  37.     void             *addr;
  38. } ngx_slab_pool_t;


  39. void ngx_slab_sizes_init(void);
  40. void ngx_slab_init(ngx_slab_pool_t *pool);
  41. void *ngx_slab_alloc(ngx_slab_pool_t *pool, size_t size);
  42. void *ngx_slab_alloc_locked(ngx_slab_pool_t *pool, size_t size);
  43. void *ngx_slab_calloc(ngx_slab_pool_t *pool, size_t size);
  44. void *ngx_slab_calloc_locked(ngx_slab_pool_t *pool, size_t size);
  45. void ngx_slab_free(ngx_slab_pool_t *pool, void *p);
  46. void ngx_slab_free_locked(ngx_slab_pool_t *pool, void *p);


  47. #endif /* _NGX_SLAB_H_INCLUDED_ */