]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mempool: introduce new helper pool_ptr()
authorLennart Poettering <lennart@poettering.net>
Tue, 14 Feb 2023 12:40:40 +0000 (13:40 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 17 Feb 2023 14:02:18 +0000 (15:02 +0100)
This new helper returns the beginning of the usable area of the pool
object.

For now this is only used once, a later commit will use it more.

src/basic/mempool.c

index 29f72a81712dee749c1b9aa9b67711d26a51a1fa..d934aa95475c8b9ef8ff0abaf96442ff531372ba 100644 (file)
@@ -13,6 +13,10 @@ struct pool {
         size_t n_used;
 };
 
+static void* pool_ptr(struct pool *p) {
+        return ((uint8_t*) ASSERT_PTR(p)) + ALIGN(sizeof(struct pool));
+}
+
 void* mempool_alloc_tile(struct mempool *mp) {
         size_t i;
 
@@ -54,7 +58,7 @@ void* mempool_alloc_tile(struct mempool *mp) {
 
         i = mp->first_pool->n_used++;
 
-        return ((uint8_t*) mp->first_pool) + ALIGN(sizeof(struct pool)) + i*mp->tile_size;
+        return (uint8_t*) pool_ptr(mp->first_pool) + i*mp->tile_size;
 }
 
 void* mempool_alloc0_tile(struct mempool *mp) {