aboutsummaryrefslogtreecommitdiff
path: root/mem/include
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2023-07-17 09:06:14 -0700
committer3gg <3gg@shellblade.net>2023-07-17 09:06:14 -0700
commitced89ff7989fde2f3d1828c9be70600d70d72e3d (patch)
tree8c27f6243325f090b08e678e5e28b2055adffcef /mem/include
parent7ab7d7d5b836d2595c5dc2c6db90c489f6768246 (diff)
Add used list to mempool; fix mem iteration.
Diffstat (limited to 'mem/include')
-rw-r--r--mem/include/mem.h24
1 files changed, 13 insertions, 11 deletions
diff --git a/mem/include/mem.h b/mem/include/mem.h
index b3d9157..bcff39f 100644
--- a/mem/include/mem.h
+++ b/mem/include/mem.h
@@ -92,17 +92,19 @@
92/// The caller can use 'i' as the index of the current chunk. 92/// The caller can use 'i' as the index of the current chunk.
93/// 93///
94/// It is valid to mem_free() the chunk at each step of the iteration. 94/// It is valid to mem_free() the chunk at each step of the iteration.
95#define mem_foreach(MEM, ITER, BODY) \ 95#define mem_foreach(MEM, ITER, BODY) \
96 size_t i = 0; \ 96 { \
97 do { \ 97 size_t i = 0; \
98 if ((MEM)->mem.chunks[i].used) { \ 98 do { \
99 __typeof__((MEM)->object[0])* ITER = \ 99 if ((MEM)->mem.chunks[i].used) { \
100 &(((__typeof__((MEM)->object[0])*)(MEM)->mem.blocks))[i]; \ 100 __typeof__((MEM)->object[0])* ITER = \
101 (void)ITER; \ 101 &(((__typeof__((MEM)->object[0])*)(MEM)->mem.blocks))[i]; \
102 BODY; \ 102 (void)ITER; \
103 } \ 103 BODY; \
104 i = (MEM)->chunks[i].next; \ 104 } \
105 } while (i); 105 i = (MEM)->mem.chunks[i].next; \
106 } while (i); \
107 }
106 108
107// ----------------------------------------------------------------------------- 109// -----------------------------------------------------------------------------
108 110