Changeset 212fc04 in git for omalloc/omAlloc.c


Ignore:
Timestamp:
Nov 22, 1999, 7:13:00 PM (24 years ago)
Author:
Olaf Bachmann <obachman@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
6ea5825fc0e0bfabf56883aee9dac9b5bbe415fe
Parents:
e6908a0f43ea328a1aa0c3942e8d309db7de26d5
Message:
* as we go along


git-svn-id: file:///usr/local/Singular/svn/trunk@3878 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • omalloc/omAlloc.c

    re6908a0 r212fc04  
    44 *  Author:  obachman@mathematik.uni-kl.de (Olaf Bachmann)
    55 *  Created: 11/99
    6  *  Version: $Id: omAlloc.c,v 1.1.1.1 1999-11-18 17:45:53 obachman Exp $
     6 *  Version: $Id: omAlloc.c,v 1.2 1999-11-22 18:12:57 obachman Exp $
    77 *******************************************************************/
    88#ifndef OM_ALLOC_C
     
    2525
    2626
    27 #if 0
    28 #include "mmemory.h"
    29 #else
    3027#include <stdlib.h>
    31 #define AllocSizeOf(x) malloc(sizeof(x))
    32 #define FreeSizeOf(addr, x) free(addr)
    33 #endif
     28#define AllocSizeOf(x) _omAllocBlock(sizeof(x))
     29#define FreeSizeOf(addr, x) _omFreeBin(addr)
    3430
    3531/* Get new page and initialize */
     
    129125
    130126/* bin->current_page is empty, get new bin->current_page, return addr*/
    131 void* omAllocBinFromFullPage(omBinPage page, omBin bin)
     127void* omAllocBinFromFullPage(omBin bin)
    132128{
    133129  void* addr;
     
    135131  omAssume(bin->current_page->current == NULL);
    136132 
     133  if (bin->current_page != om_ZeroPage)
     134  {
     135    omAssume(bin->last_page != NULL);
     136    bin->current_page->used_blocks = 0;
     137  }
     138
    137139  if (bin->current_page->next != NULL)
    138140  {
     
    154156}
    155157
    156 void* omAllocBlockFromFullPage(omBinPage page, omBin bin,
    157                                const size_t size, const int zero)
    158 {
    159   void* addr;
    160  
    161   if (bin == om_LargeBin)
    162   {
    163     addr = omMallocFromSystem(size + SIZEOF_OM_ALIGNMENT);
    164     if (zero) memset(addr, 0, size);
    165     return addr;
    166   }
    167   else
    168   {
    169     addr = omAllocBinFromFullPage(page, bin);
    170     if (zero) omMemsetW(addr, 0, bin->sizeW);
    171     return addr;
    172   }
    173 }
    174158
    175159/* page->used_blocks == 0, so, either free page or reallocate to
     
    194178  else
    195179  {
    196     bin = omBinOfPage(page);
     180    bin = omGetBinOfPage(page);
    197181    if (page->current != NULL || bin->max_blocks <= 1)
    198182    {
     
    277261    s_bin->bin->current_page = om_ZeroPage;
    278262    s_bin->bin->last_page = NULL;
     263    s_bin->bin->next = NULL;
    279264    s_bin->bin->sizeW = sizeW;
    280265    s_bin->bin->max_blocks = max_blocks;
     
    396381}
    397382
    398 static void omPrintBinStat(FILE * fd, omBin bin)
     383void omPrintBinStat(FILE * fd, omBin bin)
    399384{
    400385  int pages = 0, used_blocks = 0, free_blocks = 0;
     
    432417}
    433418 
    434 #if 0   
    435419/*****************************************************************
    436420 *
     
    485469{
    486470  omBin s_bin;
    487   omCheckBin(bin);
    488471  s_bin = omGetStickyBin(bin, sticky_tag);
    489472 
     
    506489}
    507490
    508 void omUnsetStickyBinTag(omBin bin, unsigned long sticky)
     491void omUnSetStickyBinTag(omBin bin, unsigned long sticky)
    509492{
    510493  omAssume(omGetStickyBin(bin, 0) != NULL);
     
    515498static void omMergeStickyPages(omBin to_bin, omBin from_bin)
    516499{
     500#ifdef HAVE_OM_ASSUME
     501  int length = omGListLength(to_bin->last_page, prev) +
     502    omGListLength(from_bin->last_page, prev);
     503#endif 
     504 
    517505  omBinPage page = from_bin->last_page;
     506  omAssume(to_bin->sticky == 0);
     507  omAssume(to_bin->sizeW == from_bin->sizeW);
     508  omAssume(to_bin != from_bin);
     509  omAssume(omIsOnGList(to_bin->next, next, from_bin)
     510           ||
     511           omIsOnGList(from_bin->next, next, to_bin));
    518512
    519513  if (page == NULL) return;
     
    528522  if (to_bin->last_page == NULL)
    529523  {
     524    omAssume(to_bin->current_page == om_ZeroPage);
    530525    to_bin->last_page = from_bin->last_page;
    531526    to_bin->current_page = from_bin->current_page;
     
    533528  }
    534529 
     530  omAssume(to_bin->current_page != om_ZeroPage &&
     531           to_bin->current_page != NULL);
     532
    535533  if (to_bin->current_page->current != NULL)
    536534  {
     
    544542    to_bin->current_page = to_bin->current_page->prev;
    545543  }
    546  
    547   if (to_bin->current_page->prev != NULL)
    548   {
    549     to_bin->current_page->prev->next = page;
    550     page->prev = to_bin->current_page->prev;
    551   }
    552   from_bin->last_page->next = to_bin->current_page;
    553   to_bin->current_page->prev = from_bin->last_page;
     544  else
     545  {
     546    /* need to reset this here, since new current_page is going to be
     547       from_bin->current_page, and only for current_page may we have
     548       used_blocks != 0 && current == NULL */
     549    to_bin->current_page->used_blocks = 0;
     550  }
     551 
     552
     553  omAssume(to_bin->current_page != NULL &&
     554           to_bin->current_page->current == NULL &&
     555           to_bin->current_page->used_blocks == 0);
     556
     557  from_bin->last_page->next = to_bin->current_page->next;
     558  if (to_bin->current_page->next != NULL)
     559    to_bin->current_page->next->prev =  from_bin->last_page;
     560  else
     561  {
     562    omAssume(to_bin->current_page == to_bin->last_page);
     563    to_bin->last_page = from_bin->last_page;
     564  }
     565  to_bin->current_page->next = page;
     566  page->prev = to_bin->current_page;
    554567  to_bin->current_page = from_bin->current_page;
    555 }
     568 
     569#ifdef HAVE_OM_ASSUME
     570  omAssume(omGListLength(to_bin->last_page, prev) == length);
     571#endif
     572}
     573
     574#include "omDebug.h"
    556575 
    557576void omDeleteStickyBinTag(omBin bin, unsigned long sticky)
     
    559578  omBin no_sticky_bin = NULL;
    560579  omBin sticky_bin = NULL;
    561  
     580
     581  omdCheckBin(bin, 10);
    562582  if (sticky == 0)
    563583  {
     
    566586  }
    567587 
    568   omCheckBin(bin);
    569  
    570588  sticky_bin = omGetStickyBin(bin, sticky);
    571589  if (sticky_bin != NULL)
     
    575593
    576594    omMergeStickyPages(no_sticky_bin, sticky_bin);
    577     omCheckBin(no_sticky_bin);
    578595
    579596    if (bin == sticky_bin)
     
    585602    FreeSizeOf(sticky_bin, omBin_t);
    586603  }
    587   omCheckBin(bin);
     604  omdCheckBin(bin, 10);
    588605}
    589606
     
    595612*
    596613*****************************************************************/
    597 
    598 #ifdef BIN_DEBUG
    599 static BOOLEAN omIsKnownBin(omBin bin)
    600 {
    601   int i;
    602   mem_SpecBin s_bin;
    603  
    604   for (i=0; i<=MAX_BIN_INDEX; i++)
    605   {
    606     if (bin == &om_StaticBin[i]) return TRUE;
    607   }
    608  
    609   mem_SpecBin s_bin = om_SpecBins;
    610   while (s_bin != NULL)
    611   {
    612     if (s_bin->bin == bin) return TRUE;
    613     s_bin = s_bin->next;
    614   }
    615   return FALSE;
    616 }
    617 
    618 static BOOLEAN omDebugCheckAllBins(const char* fn, int l)
    619 {
    620   int i;
    621   mem_SpecBin s_bin = om_SpecBins;
    622   BOOLEAN return = TRUE;
    623   for (i=0; i<=MAX_BIN_INDEX; i++)
    624   {
    625     ret = ret && omDebugCheckBin(&(om_StaticBin[i]), fn, l);
    626   }
    627   while (s_bin != NULL)
    628   {
    629     ret = ret && omDebugCheckBin(s_bin->bin, fn, l);
    630     s_bin = s_bin->next;
    631   }
    632   return ret;
    633 }
    634 #endif
    635 
    636 
    637614unsigned long omGetNewStickyAllBinTag()
    638615{
     
    641618  omSpecBin s_bin;
    642619  // first, find new sticky tag
    643   for (i=0; i<=MAX_BIN_INDEX; i++)
     620  for (i=0; i<=OM_MAX_BIN_INDEX; i++)
    644621  {
    645622    new_sticky = omGetMaxStickyBinTag(&(om_StaticBin[i]));
    646623    if (new_sticky > sticky) sticky = new_sticky;
    647624  }
     625  s_bin = om_SpecBin;
    648626  while (s_bin != NULL)
    649627  {
     
    655633  {
    656634    sticky++;
    657     for (i=0; i<=MAX_BIN_INDEX; i++)
     635    for (i=0; i<=OM_MAX_BIN_INDEX; i++)
    658636    {
    659637      omCreateStickyBin(&(om_StaticBin[i]), sticky);
     
    671649    omBin bin;
    672650    omAssume(sticky == BIT_SIZEOF_LONG - 1);
    673     for (i=0; i<=MAX_BIN_INDEX; i++)
     651    for (i=0; i<=OM_MAX_BIN_INDEX; i++)
    674652    {
    675653      bin = &om_StaticBin[i];
     
    692670  omSpecBin s_bin = om_SpecBin;
    693671  int i;
    694   for (i=0; i<=MAX_BIN_INDEX; i++)
     672  for (i=0; i<=OM_MAX_BIN_INDEX; i++)
    695673  {
    696674    omSetStickyBinTag(&(om_StaticBin[i]), sticky);
     
    707685  omSpecBin s_bin = om_SpecBin;
    708686  int i;
    709   for (i=0; i<=MAX_BIN_INDEX; i++)
     687  for (i=0; i<=OM_MAX_BIN_INDEX; i++)
    710688  {
    711689    omUnSetStickyBinTag(&(om_StaticBin[i]), sticky);
     
    722700  omSpecBin s_bin = om_SpecBin;
    723701  int i;
    724   for (i=0; i<=MAX_BIN_INDEX; i++)
     702  for (i=0; i<=OM_MAX_BIN_INDEX; i++)
    725703  {
    726704    omDeleteStickyBinTag(&(om_StaticBin[i]), sticky);
     
    733711}
    734712
    735 #endif                       
    736 
    737713#endif /* OM_ALLOC_C */
Note: See TracChangeset for help on using the changeset viewer.