chiark / gitweb /
mempool: add a zeroing alloc function
authorMichal Schmidt <mschmidt@redhat.com>
Fri, 24 Oct 2014 13:30:18 +0000 (15:30 +0200)
committerMichal Schmidt <mschmidt@redhat.com>
Thu, 30 Oct 2014 18:50:50 +0000 (19:50 +0100)
Add mempool_alloc0_tile(). It's like mempool_alloc_tile(), but it
initializes the allocated tile's memory to zero.

src/shared/mempool.c
src/shared/mempool.h

index b39a37f2db480c68499851bc910c2a071d815ad1..d5d98d88294d365ec0410fd755996c318d144429 100644 (file)
@@ -74,6 +74,15 @@ void* mempool_alloc_tile(struct mempool *mp) {
         return ((uint8_t*) mp->first_pool) + ALIGN(sizeof(struct pool)) + i*mp->tile_size;
 }
 
+void* mempool_alloc0_tile(struct mempool *mp) {
+        void *p;
+
+        p = mempool_alloc_tile(mp);
+        if (p)
+                memzero(p, mp->tile_size);
+        return p;
+}
+
 void mempool_free_tile(struct mempool *mp, void *p) {
         * (void**) p = mp->freelist;
         mp->freelist = p;
index 8b0bf381bf7f1c3b9c97c9d89814989b4bf0f9c0..42f473bee10e0291bbef952be2abfb079ed8c117 100644 (file)
@@ -34,6 +34,7 @@ struct mempool {
 };
 
 void* mempool_alloc_tile(struct mempool *mp);
+void* mempool_alloc0_tile(struct mempool *mp);
 void mempool_free_tile(struct mempool *mp, void *p);
 
 #define DEFINE_MEMPOOL(pool_name, tile_type, alloc_at_least) \