]> mj.ucw.cz Git - libucw.git/blobdiff - lib/pools.h
I decided to turn off cf/url-equiv for indexation. however, after the indexer
[libucw.git] / lib / pools.h
index 861cf82a241e58fda46407d5fe649a926e0eb747..a055ef2623763f2da93ca77632ca60d168df9c7d 100644 (file)
@@ -1,37 +1,63 @@
 /*
  *     Sherlock Library -- Memory Pools
  *
- *     (c) 1997 Martin Mares, <mj@atrey.karlin.mff.cuni.cz>
+ *     (c) 1997--2003 Martin Mares <mj@ucw.cz>
+ *
+ *     This software may be freely distributed and used according to the terms
+ *     of the GNU Lesser General Public License.
  */
 
-#define POOL_ALIGN 4
+#ifndef _SHERLOCK_POOLS_H
+#define _SHERLOCK_POOLS_H
+
+#ifndef POOL_ALIGN
+#define POOL_ALIGN CPU_STRUCT_ALIGN
+#endif
 
 struct mempool {
-  struct memchunk *chunks;
   byte *free, *last;
+  struct memchunk *first, *current, **plast;
+  struct memchunk *first_large;
   uns chunk_size, threshold;
 };
 
-struct mempool *new_pool(uns);
-void free_pool(struct mempool *);
-void *pool_alloc(struct mempool *, uns);
+struct mempool *mp_new(uns);
+void mp_delete(struct mempool *);
+void mp_flush(struct mempool *);
+void *mp_alloc(struct mempool *, uns);
+void *mp_alloc_zero(struct mempool *, uns);
 
-extern inline void *fast_alloc(struct mempool *p, uns l)
+static inline void *mp_alloc_fast(struct mempool *p, uns l)
 {
-  void *f = (void *) (((uns) p->free + POOL_ALIGN - 1) & ~(POOL_ALIGN - 1));
+  byte *f = (void *) (((uns) p->free + POOL_ALIGN - 1) & ~(POOL_ALIGN - 1));
   byte *ee = f + l;
   if (ee > p->last)
-    return pool_alloc(p, l);
+    return mp_alloc(p, l);
   p->free = ee;
   return f;
 }
 
-extern inline void *fast_alloc_noalign(struct mempool *p, uns l)
+static inline void *mp_alloc_fast_noalign(struct mempool *p, uns l)
 {
-  void *f = p->free;
+  byte *f = p->free;
   byte *ee = f + l;
   if (ee > p->last)
-    return pool_alloc(p, l);
+    return mp_alloc(p, l);
   p->free = ee;
   return f;
 }
+
+static inline void *
+mp_start_string(struct mempool *p, uns l)
+{
+  ASSERT(l <= p->chunk_size);
+  return mp_alloc(p, l);
+}
+
+static inline void
+mp_end_string(struct mempool *p, void *stop)
+{
+  p->free = stop;
+}
+
+#endif