]> mj.ucw.cz Git - libucw.git/commitdiff
Better version of clearable pools.
authorMartin Mares <mj@ucw.cz>
Mon, 25 Oct 1999 07:54:28 +0000 (07:54 +0000)
committerMartin Mares <mj@ucw.cz>
Mon, 25 Oct 1999 07:54:28 +0000 (07:54 +0000)
lib/pool.c

index 8c352f0fa9f83081cbf92551fa09179a52375958..7fc635d37cf11aa2a8df98ed934f08153f614954 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *     Sherlock Library -- Memory Pools (One-Time Allocation)
  *
- *     (c) 1997 Martin Mares, <mj@atrey.karlin.mff.cuni.cz>
+ *     (c) 1997--1999 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
  */
 
 #include <stdio.h>
@@ -71,9 +71,12 @@ pool_alloc(struct mempool *p, uns s)
        {
          struct memchunk *c;
 
-         if (p->current && p->current->next)
-           /* Still have free chunks from previous incarnation */
-           c = p->current->next;
+         if (p->current)
+           {
+             /* Still have free chunks from previous incarnation */
+             c = p->current;
+             p->current = c->next;
+           }
          else
            {
              c = xmalloc(sizeof(struct memchunk) + p->chunk_size);
@@ -81,7 +84,6 @@ pool_alloc(struct mempool *p, uns s)
              p->plast = &c->next;
              c->next = NULL;
            }
-         p->current = c;
          x = c->data;
          p->last = x + p->chunk_size;
        }