pike.git / src / block_allocator.c

version» Context lines:

pike.git/src/block_allocator.c:1:   #include <stdlib.h>   #include <string.h>   #include <stdint.h>    - #include "post_modules/Critbit/bitvector.h" + #include "post_modules/CritBit/bitvector.h"   #define __PIKE__   #ifdef __PIKE__   # include "pike_error.h"   #endif      #define BA_SEGREGATE      struct ba_page {    char * data;    uint16_t next, prev;
pike.git/src/block_allocator.c:353:    }   #else    if (p->blocks_used == a->blocks) Pike_error("baaad!\n");    p->blocks_used ++;    ptr = BA_BLOCKN(a, p, p->first-1);    //fprintf(stderr, "alloced pointer %p (%u/%u used %u)\n",    //ptr, p->first-1, a->blocks, p->blocks_used);       if (unlikely(p->blocks_used == a->blocks)) {    a->first = p->next; +  BA_PAGE(a, a->first)->prev = 0;    if (!a->first) {    a->last = 0;    }    p->next = 0;    } else {    //fprintf(stderr, "next: %u\n", ((struct ba_block_header*)ptr)->next);    if (((struct ba_block_header*)ptr)->next)    p->first = ((struct ba_block_header*)ptr)->next;    else p->first++;    }
pike.git/src/block_allocator.c:530:    p->data, BA_LASTBLOCK(a, p), hash1(a, BA_LASTBLOCK(a,p)),    hash1(a, BA_LASTBLOCK(a,p)) & BA_HASH_MASK(a),    a->num_pages);    */       ba_htable_delete(a, BA_LASTBLOCK(a, p), n);       free(p->data);    p->data = NULL;    -  if (a->num_pages != n) { -  tmp = BA_PAGE(a, a->num_pages); -  ba_htable_replace(a, BA_LASTBLOCK(a, tmp), a->num_pages, n); -  /* -  fprintf(stderr, "replacing with page %u\t(%p .. %p) -> %X (%X)\n", -  a->num_pages, -  tmp->data, BA_LASTBLOCK(a, tmp), hash1(a, BA_LASTBLOCK(a,tmp)), -  hash1(a, BA_LASTBLOCK(a,tmp)) & BA_HASH_MASK(a) -  ); -  */ -  *p = *tmp; -  } +        if (a->last_free == n)    a->last_free = 0;    else if (a->last_free == a->num_pages)    a->last_free = n;       if (p->prev) {    tmp = BA_PAGE(a, p->prev);    tmp->next = p->next;    } else {    a->first = p->next;    }       if (p->next) {    tmp = BA_PAGE(a, p->next);    tmp->prev = p->prev;    } else {    a->last = p->prev;    }    -  +  if (a->num_pages != n) { +  tmp = BA_PAGE(a, a->num_pages); +  ba_htable_replace(a, BA_LASTBLOCK(a, tmp), a->num_pages, n); +  /* +  fprintf(stderr, "replacing with page %u\t(%p .. %p) -> %X (%X)\n", +  a->num_pages, +  tmp->data, BA_LASTBLOCK(a, tmp), hash1(a, BA_LASTBLOCK(a,tmp)), +  hash1(a, BA_LASTBLOCK(a,tmp)) & BA_HASH_MASK(a) +  ); +  */ +  *p = *tmp; +  if (p->next) BA_PAGE(a, p->next)->prev = n; +  if (p->prev) BA_PAGE(a, p->prev)->next = n; +  if (a->num_pages == a->first) { +  a->first = n; +  } +  } +  +  memset(BA_PAGE(a, a->num_pages), 0, sizeof(struct ba_page)); +     a->num_pages--;   }