Diff for /libaitsess/src/Attic/mem.c between versions 1.1.2.7 and 1.1.2.10

version 1.1.2.7, 2012/02/28 10:34:43 version 1.1.2.10, 2012/02/28 12:44:18
Line 168  void * Line 168  void *
 mpool_malloc(mpool_t * __restrict mp, u_int size, const char *memname)  mpool_malloc(mpool_t * __restrict mp, u_int size, const char *memname)
 {  {
         struct tagAlloc *m;          struct tagAlloc *m;
        int idx, align;        int idx;
         u_int align;
   
         if (!mp) {          if (!mp) {
                 sess_SetErr(EINVAL, "Pool not specified");                  sess_SetErr(EINVAL, "Pool not specified");
Line 243  void * Line 244  void *
 mpool_realloc(mpool_t * __restrict mp, void * __restrict data, u_int newsize, const char *memname)  mpool_realloc(mpool_t * __restrict mp, void * __restrict data, u_int newsize, const char *memname)
 {  {
         struct tagAlloc *m, *tmp;          struct tagAlloc *m, *tmp;
        int idx, align, oidx, osize;        int idx, oidx;
         void *p;          void *p;
           u_int align, osize;
   
         /* if !data execute mpool_malloc() */          /* if !data execute mpool_malloc() */
         if (!data)          if (!data)
Line 275  mpool_realloc(mpool_t * __restrict mp, void * __restri Line 277  mpool_realloc(mpool_t * __restrict mp, void * __restri
   
         /* quota */          /* quota */
         if (mp->pool_quota.max &&           if (mp->pool_quota.max && 
                        (mp->pool_quota.curr + (newsize - osize)) > mp->pool_quota.max) {                        (mp->pool_quota.curr + ((u_long) newsize - osize)) > mp->pool_quota.max) {
                 sess_SetErr(ENOMEM, "Max.allocate memory quota has been reached");                  sess_SetErr(ENOMEM, "Max.allocate memory quota has been reached");
                 mpool_unlock(mp);                  mpool_unlock(mp);
                 return NULL;                  return NULL;
         }          }
   
         /* find old memory block */          /* find old memory block */
        TAILQ_FOREACH_SAFE(m, &mp->pool_active[oidx], alloc_node, tmp)        TAILQ_FOREACH_SAFE(m, &mp->pool_active[oidx], alloc_node, tmp) {
                 if (mem_data(m, void*) == data && mem_size(m) == osize) {                  if (mem_data(m, void*) == data && mem_size(m) == osize) {
                        TAILQ_REMOVE(&mp->pool_active[oidx], m, alloc_node);                        /* case in different buckets */
                        /* statistics */                        if (oidx != idx) {
                        mp->pool_calls.alloc--;                                TAILQ_REMOVE(&mp->pool_active[oidx], m, alloc_node);
                                 /* statistics */
                                 mp->pool_calls.alloc--;
                         }
                         mp->pool_bytes.alloc -= osize;                          mp->pool_bytes.alloc -= osize;
                           break;
                 }                  }
           }
         /* memory block not found! */          /* memory block not found! */
         if (!m) {          if (!m) {
                 mpool_unlock(mp);                  mpool_unlock(mp);
Line 297  mpool_realloc(mpool_t * __restrict mp, void * __restri Line 304  mpool_realloc(mpool_t * __restrict mp, void * __restri
         }          }
   
         /* try to reallocate memory block to new bucket */          /* try to reallocate memory block to new bucket */
        align = 1 << (idx + MEM_MIN_BUCKET);        if (oidx != idx) {
        p = realloc(m->alloc_mem, align + 12);                align = 1 << (idx + MEM_MIN_BUCKET);
        if (!p) {                p = realloc(m->alloc_mem, align + 12);
                LOGERR;                if (!p) {
                         LOGERR;
   
                /* restore to old bucket pulled memory block for reallocation */                        /* restore to old bucket pulled memory block for reallocation */
                TAILQ_INSERT_HEAD(&mp->pool_active[oidx], m, alloc_node);                        TAILQ_INSERT_HEAD(&mp->pool_active[oidx], m, alloc_node);
                /* statistics */                        /* statistics */
                mp->pool_calls.alloc++;                        mp->pool_calls.alloc++;
                mp->pool_bytes.alloc += osize;                        mp->pool_bytes.alloc += osize;
   
                mpool_unlock(mp);                        mpool_unlock(mp);
                return NULL;                        return NULL;
        } else  /* quota */                } else
                mp->pool_quota.curr += (newsize - osize);                        m->alloc_mem = (u_int*) p;
         }
         /* quota */
         mp->pool_quota.curr += (u_long) newsize - osize;
   
         m->alloc_mem[0] = newsize / sizeof(u_int);          m->alloc_mem[0] = newsize / sizeof(u_int);
         m->alloc_mem[1] = MEM_MAGIC_START;          m->alloc_mem[1] = MEM_MAGIC_START;
         m->alloc_mem[2 + newsize / sizeof(u_int)] = MEM_MAGIC_STOP;          m->alloc_mem[2 + newsize / sizeof(u_int)] = MEM_MAGIC_STOP;
        TAILQ_INSERT_HEAD(&mp->pool_active[idx], m, alloc_node);
        /* statistics */        if (oidx != idx) {
        mp->pool_calls.alloc++;                TAILQ_INSERT_HEAD(&mp->pool_active[idx], m, alloc_node);
                 /* statistics */
                 mp->pool_calls.alloc++;
         }
         mp->pool_bytes.alloc += newsize;          mp->pool_bytes.alloc += newsize;
   
         if (memname)          if (memname)

Removed from v.1.1.2.7  
changed lines
  Added in v.1.1.2.10


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>