1 2/* 3 * Copyright (C) Igor Sysoev 4 * Copyright (C) NGINX, Inc. 5 */ 6 7#ifndef _NXT_LIST_H_INCLUDED_ 8#define _NXT_LIST_H_INCLUDED_ 9 10 11typedef struct nxt_list_part_s nxt_list_part_t; 12 13struct nxt_list_part_s { 14 nxt_list_part_t *next; 15 uintptr_t nelts; 16 char data[]; 17}; 18 19 20typedef struct { 21 nxt_list_part_t *last; 22#if (NXT_64BIT) 23 uint32_t size; 24 uint32_t nalloc; 25#else 26 uint16_t size; 27 uint16_t nalloc; 28#endif 29 nxt_mp_t *mem_pool; 30 nxt_list_part_t part; 31} nxt_list_t; 32 33 34typedef struct { 35 nxt_list_part_t *part; 36 uintptr_t elt; 37} nxt_list_next_t; 38 39
| 1 2/* 3 * Copyright (C) Igor Sysoev 4 * Copyright (C) NGINX, Inc. 5 */ 6 7#ifndef _NXT_LIST_H_INCLUDED_ 8#define _NXT_LIST_H_INCLUDED_ 9 10 11typedef struct nxt_list_part_s nxt_list_part_t; 12 13struct nxt_list_part_s { 14 nxt_list_part_t *next; 15 uintptr_t nelts; 16 char data[]; 17}; 18 19 20typedef struct { 21 nxt_list_part_t *last; 22#if (NXT_64BIT) 23 uint32_t size; 24 uint32_t nalloc; 25#else 26 uint16_t size; 27 uint16_t nalloc; 28#endif 29 nxt_mp_t *mem_pool; 30 nxt_list_part_t part; 31} nxt_list_t; 32 33 34typedef struct { 35 nxt_list_part_t *part; 36 uintptr_t elt; 37} nxt_list_next_t; 38 39
|
40#define \ 41nxt_list_part(list) \
| 40#define nxt_list_part(list) \
|
42 (&(list)->part) 43 44
| 41 (&(list)->part) 42 43
|
45#define \ 46nxt_list_data(part) \
| 44#define nxt_list_data(part) \
|
47 ((void *) part->data) 48 49
| 45 ((void *) part->data) 46 47
|
50#define \ 51nxt_list_first(list) \
| 48#define nxt_list_first(list) \
|
52 nxt_list_data(nxt_list_part(list)) 53 54 55nxt_inline void * 56nxt_list_elt(nxt_list_t *list, nxt_uint_t n) 57{ 58 nxt_list_part_t *part; 59 60 if (nxt_fast_path((list) != NULL)) { 61 part = nxt_list_part(list); 62 63 while (part != NULL) { 64 if (n < (nxt_uint_t) part->nelts) { 65 return nxt_pointer_to(nxt_list_data(part), n * (list)->size); 66 } 67 68 n -= (nxt_uint_t) part->nelts; 69 part = part->next; 70 } 71 } 72 73 return NULL; 74} 75 76 77#define nxt_list_each(elt, list) \ 78 do { \ 79 if (nxt_fast_path((list) != NULL)) { \ 80 void *_end; \ 81 nxt_list_part_t *_part = nxt_list_part(list); \ 82 \ 83 do { \ 84 elt = nxt_list_data(_part); \ 85 \ 86 for (_end = (elt + _part->nelts); elt != _end; elt++) { \ 87 88#define nxt_list_loop \ 89 } \ 90 \ 91 _part = _part->next; \ 92 \ 93 } while (_part != NULL); \ 94 } \ 95 } while (0) 96 97 98NXT_EXPORT nxt_list_t *nxt_list_create(nxt_mp_t *mp, nxt_uint_t n, size_t size); 99NXT_EXPORT void *nxt_list_add(nxt_list_t *list); 100NXT_EXPORT void *nxt_list_zero_add(nxt_list_t *list); 101 102NXT_EXPORT void *nxt_list_next(nxt_list_t *list, nxt_list_next_t *next); 103 104
| 49 nxt_list_data(nxt_list_part(list)) 50 51 52nxt_inline void * 53nxt_list_elt(nxt_list_t *list, nxt_uint_t n) 54{ 55 nxt_list_part_t *part; 56 57 if (nxt_fast_path((list) != NULL)) { 58 part = nxt_list_part(list); 59 60 while (part != NULL) { 61 if (n < (nxt_uint_t) part->nelts) { 62 return nxt_pointer_to(nxt_list_data(part), n * (list)->size); 63 } 64 65 n -= (nxt_uint_t) part->nelts; 66 part = part->next; 67 } 68 } 69 70 return NULL; 71} 72 73 74#define nxt_list_each(elt, list) \ 75 do { \ 76 if (nxt_fast_path((list) != NULL)) { \ 77 void *_end; \ 78 nxt_list_part_t *_part = nxt_list_part(list); \ 79 \ 80 do { \ 81 elt = nxt_list_data(_part); \ 82 \ 83 for (_end = (elt + _part->nelts); elt != _end; elt++) { \ 84 85#define nxt_list_loop \ 86 } \ 87 \ 88 _part = _part->next; \ 89 \ 90 } while (_part != NULL); \ 91 } \ 92 } while (0) 93 94 95NXT_EXPORT nxt_list_t *nxt_list_create(nxt_mp_t *mp, nxt_uint_t n, size_t size); 96NXT_EXPORT void *nxt_list_add(nxt_list_t *list); 97NXT_EXPORT void *nxt_list_zero_add(nxt_list_t *list); 98 99NXT_EXPORT void *nxt_list_next(nxt_list_t *list, nxt_list_next_t *next); 100 101
|
105#define \ 106nxt_list_next_value(list, next) \
| 102#define nxt_list_next_value(list, next) \
|
107 (nxt_pointer_to(nxt_list_data((next)->part), (next)->elt * (list)->size)) 108 109 110nxt_inline nxt_uint_t 111nxt_list_nelts(nxt_list_t *list) 112{ 113 nxt_uint_t n; 114 nxt_list_part_t *part; 115 116 n = 0; 117 118 if (nxt_fast_path((list) != NULL)) { 119 part = nxt_list_part(list); 120 121 do { 122 n += (nxt_uint_t) part->nelts; 123 part = part->next; 124 } while (part != NULL); 125 } 126 127 return n; 128} 129 130 131#endif /* _NXT_LIST_H_INCLUDED_ */
| 103 (nxt_pointer_to(nxt_list_data((next)->part), (next)->elt * (list)->size)) 104 105 106nxt_inline nxt_uint_t 107nxt_list_nelts(nxt_list_t *list) 108{ 109 nxt_uint_t n; 110 nxt_list_part_t *part; 111 112 n = 0; 113 114 if (nxt_fast_path((list) != NULL)) { 115 part = nxt_list_part(list); 116 117 do { 118 n += (nxt_uint_t) part->nelts; 119 part = part->next; 120 } while (part != NULL); 121 } 122 123 return n; 124} 125 126 127#endif /* _NXT_LIST_H_INCLUDED_ */
|