Changeset 13fe1b in git for omalloc/omBin.c


Ignore:
Timestamp:
Apr 30, 2001, 11:02:15 AM (23 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', '2a584933abf2a2d3082034c7586d38bb6de1a30a')
Children:
4d59e4136d84df15b329a224051e410d9f7ac557
Parents:
38f6b334b77a57a06e357ad3a927916497dcb9bf
Message:
*hannes: DecAlpha-ccc-port


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

Legend:

Unmodified
Added
Removed
  • omalloc/omBin.c

    r38f6b33 r13fe1b  
    44 *  Author:  obachman (Olaf Bachmann)
    55 *  Created: 11/99
    6  *  Version: $Id: omBin.c,v 1.6 2000-12-12 15:26:15 obachman Exp $
     6 *  Version: $Id: omBin.c,v 1.7 2001-04-30 09:02:02 Singular Exp $
    77 *******************************************************************/
    88
     
    4040#else
    4141  align = 0;
    42 #endif 
    43  
     42#endif
     43
    4444  if (size > SIZEOF_OM_BIN_PAGE)
    4545  {
    4646    /* need page header */
    47     max_blocks = - (long) 
     47    max_blocks = - (long)
    4848      ((size+(SIZEOF_SYSTEM_PAGE-SIZEOF_OM_BIN_PAGE))+SIZEOF_SYSTEM_PAGE-1)
    4949      / SIZEOF_SYSTEM_PAGE;
    50     sizeW = ((-max_blocks*SIZEOF_SYSTEM_PAGE) - 
     50    sizeW = ((-max_blocks*SIZEOF_SYSTEM_PAGE) -
    5151             (SIZEOF_SYSTEM_PAGE - SIZEOF_OM_BIN_PAGE)) / SIZEOF_LONG;
    5252    om_new_specBin = om_LargeBin;
     
    6464#endif
    6565      sizeW = ((size + sizeW) & ~ (SIZEOF_OM_ALIGNMENT - 1));
    66    
     66
    6767    omAssume(sizeW >= size);
    6868    omAssume(max_blocks*sizeW <= SIZEOF_OM_BIN_PAGE);
     
    8787    }
    8888#endif
    89     else 
     89    else
    9090    {
    9191      om_new_specBin = omSmallSize2Bin( size );
     
    104104      s_bin = omFindInSortedGList(om_SpecBin, next, max_blocks, max_blocks);
    105105
    106     if (s_bin != NULL) 
     106    if (s_bin != NULL)
    107107    {
    108108      (s_bin->ref)++;
    109       omAssume(s_bin->bin != NULL && 
     109      omAssume(s_bin->bin != NULL &&
    110110             s_bin->bin->max_blocks == s_bin->max_blocks &&
    111111             s_bin->bin->sizeW == sizeW);
     
    144144  if (! omIsStaticBin(bin))
    145145  {
    146 #ifdef OM_HAVE_TRACK 
     146#ifdef OM_HAVE_TRACK
    147147    int track_bin = 0;
    148 #endif 
     148#endif
    149149    omSpecBin s_bin;
    150150
     
    156156#endif
    157157        s_bin = omFindInSortedGList(om_SpecBin, next, max_blocks, bin->max_blocks);
    158        
     158
    159159    omAssume(s_bin != NULL && bin == s_bin->bin);
    160160    if (s_bin != NULL)
     
    164164      {
    165165#ifdef OM_HAVE_TRACK
    166         if (! track_bin) 
     166        if (! track_bin)
    167167#endif
    168168          omFreeKeptAddrFromBin(s_bin->bin);
     
    238238  omBin s_bin;
    239239  s_bin = omGetStickyBin(bin, sticky_tag);
    240  
     240
    241241  if (s_bin != bin)
    242242  {
    243243    omBinPage tc, tl;
    244244    unsigned long ts;
    245    
     245
    246246    if (s_bin == NULL) s_bin = omCreateStickyBin(bin, sticky_tag);
    247247    ts = bin->sticky;
     
    269269  int length = omGListLength(to_bin->last_page, prev) +
    270270    omGListLength(from_bin->last_page, prev);
    271 #endif 
    272  
     271#endif
     272
    273273  omBinPage page = from_bin->last_page;
    274274  omAssume(to_bin->sizeW == from_bin->sizeW);
     
    291291    return;
    292292  }
    293  
    294   omAssume(to_bin->current_page != om_ZeroPage && 
     293
     294  omAssume(to_bin->current_page != om_ZeroPage &&
    295295           to_bin->current_page != NULL);
    296296
     
    309309  {
    310310    /* need to reset this here, since new current_page is going to be
    311        from_bin->current_page, and only for current_page may we have 
     311       from_bin->current_page, and only for current_page may we have
    312312       used_blocks != 0 && current == NULL */
    313313    to_bin->current_page->used_blocks = 0;
    314314  }
    315  
    316 
    317   omAssume(to_bin->current_page != NULL && 
     315
     316
     317  omAssume(to_bin->current_page != NULL &&
    318318           to_bin->current_page->current == NULL &&
    319319           to_bin->current_page->used_blocks == 0);
    320320
    321321  from_bin->last_page->next = to_bin->current_page->next;
    322   if (to_bin->current_page->next != NULL) 
     322  if (to_bin->current_page->next != NULL)
    323323    to_bin->current_page->next->prev =  from_bin->last_page;
    324324  else
     
    330330  page->prev = to_bin->current_page;
    331331  to_bin->current_page = from_bin->current_page;
    332  
     332
    333333#ifdef HAVE_OM_ASSUME
    334334  omAssume(omGListLength(to_bin->last_page, prev) == length);
     
    346346    return;
    347347  }
    348  
     348
    349349  sticky_bin = omGetStickyBin(bin, sticky);
    350350  if (sticky_bin != NULL)
     
    355355    omMergeStickyPages(no_sticky_bin, sticky_bin);
    356356
    357     if (bin == sticky_bin) 
     357    if (bin == sticky_bin)
    358358    {
    359359      sticky_bin = no_sticky_bin;
     
    397397void omMergeStickyBinIntoBin(omBin sticky_bin, omBin into_bin)
    398398{
    399   if (! omIsOnGList(om_StickyBins, next, sticky_bin) || 
     399  if (! omIsOnGList(om_StickyBins, next, sticky_bin) ||
    400400      !sticky_bin->sticky ||
    401401      sticky_bin->max_blocks != into_bin->max_blocks ||
     
    405405  {
    406406#ifndef OM_NDEBUG
    407     omReportError(omError_StickyBin, omError_NoError, OM_FLR, 
     407    omReportError(omError_StickyBin, omError_NoError, OM_FLR,
    408408                  (! omIsOnGList(om_StickyBins, next, sticky_bin)  ? "unknown sticky_bin" :
    409                    (!sticky_bin->sticky ? "sticky_bin is not sticky" : 
     409                   (!sticky_bin->sticky ? "sticky_bin is not sticky" :
    410410                    (sticky_bin->max_blocks != into_bin->max_blocks ? "sticky_bin and into_bin have different block sizes" :
    411                      (sticky_bin == into_bin ? "sticky_bin == into_bin" : 
     411                     (sticky_bin == into_bin ? "sticky_bin == into_bin" :
    412412                      (!omIsKnownTopBin(into_bin, 1) ? "unknown into_bin" :
    413413                       (omIsStickyBin(into_bin) ? "into_bin is sticky" :
     
    430430#if defined(OM_INTERNAL_DEBUG) && !defined(OM_NDEBUG)
    431431  omTestBin(into_bin, 2);
    432 #endif 
    433 }
    434  
     432#endif
     433}
     434
    435435/*****************************************************************
    436436*
     
    444444  omSpecBin s_bin;
    445445  int i;
    446  
     446
    447447  omAssume(normal_bin == 1 || normal_bin == 0);
    448  
    449 #ifdef OM_HAVE_TRACK
    450   if (! normal_bin) 
     448
     449#ifdef OM_HAVE_TRACK
     450  if (! normal_bin)
    451451  {
    452452    to_check = om_StaticTrackBin;
    453453    s_bin = om_SpecTrackBin;
    454454  }
    455   else 
     455  else
    456456#endif
    457457  {
     
    463463  for (i=0; i<= OM_MAX_BIN_INDEX; i++)
    464464  {
    465     if (bin == &(to_check[i])) 
     465    if (bin == &(to_check[i]))
    466466      return 1;
    467467  }
    468  
     468
    469469  while (s_bin != NULL)
    470470  {
     
    495495  }
    496496  s_bin = om_SpecBin;
    497   while (s_bin != NULL) 
     497  while (s_bin != NULL)
    498498  {
    499499    new_sticky = omGetMaxStickyBinTag(s_bin->bin);
     
    501501    s_bin = s_bin->next;
    502502  }
    503   if (sticky < BIT_SIZEOF_LONG - 2) 
     503  if (sticky < BIT_SIZEOF_LONG - 2)
    504504  {
    505505    sticky++;
     
    509509    }
    510510    s_bin = om_SpecBin;
    511     while (s_bin != NULL) 
     511    while (s_bin != NULL)
    512512    {
    513513      omCreateStickyBin(s_bin->bin, sticky);
     
    527527    }
    528528    s_bin = om_SpecBin;
    529     while (s_bin != NULL) 
     529    while (s_bin != NULL)
    530530    {
    531531      if (omGetStickyBin(s_bin->bin, BIT_SIZEOF_LONG -1) == NULL)
     
    545545    omSetStickyBinTag(&(om_StaticBin[i]), sticky);
    546546  }
    547   while (s_bin != NULL) 
     547  while (s_bin != NULL)
    548548  {
    549549    omSetStickyBinTag(s_bin->bin, sticky);
     
    560560    omUnSetStickyBinTag(&(om_StaticBin[i]), sticky);
    561561  }
    562   while (s_bin != NULL) 
     562  while (s_bin != NULL)
    563563  {
    564564    omUnSetStickyBinTag(s_bin->bin, sticky);
     
    575575    omDeleteStickyBinTag(&(om_StaticBin[i]), sticky);
    576576  }
    577   while (s_bin != NULL) 
     577  while (s_bin != NULL)
    578578  {
    579579    omDeleteStickyBinTag(s_bin->bin, sticky);
     
    586586{
    587587  omBinPage page = bin->last_page;
    588  
     588
    589589  while (page != NULL)
    590590  {
    591591    void* addr = (void*) page + SIZEOF_OM_BIN_PAGE_HEADER;
    592592    int i;
    593    
     593
    594594    for (i=0; i<bin->max_blocks; i++)
    595595    {
     
    608608 *
    609609 *****************************************************************/
    610 static void omGetBinStat(omBin bin, int *pages_p, int *used_blocks_p, 
     610static void omGetBinStat(omBin bin, int *pages_p, int *used_blocks_p,
    611611                          int *free_blocks_p)
    612612{
    613613  int pages = 0, used_blocks = 0, free_blocks = 0;
    614614  int where = 1;
    615  
     615
    616616  omBinPage page = bin->last_page;
    617617  while (page != NULL)
    618618  {
    619     pages++; if (where == 1) 
     619    pages++; if (where == 1)
    620620    {
    621621      used_blocks += omGetUsedBlocksOfPage(page) + 1;
     
    623623        free_blocks += bin->max_blocks - omGetUsedBlocksOfPage(page) -1;
    624624    }
    625     else 
     625    else
    626626    {
    627627      if (bin->max_blocks > 1)
     
    638638}
    639639
    640 static void omGetTotalBinStat(omBin bin, int *pages_p, int *used_blocks_p, 
     640static void omGetTotalBinStat(omBin bin, int *pages_p, int *used_blocks_p,
    641641                               int *free_blocks_p)
    642642{
    643643  int t_pages = 0, t_used_blocks = 0, t_free_blocks = 0;
    644644  int pages = 0, used_blocks = 0, free_blocks = 0;
    645  
     645
    646646  while (bin != NULL)
    647647  {
     
    652652    if (!omIsStickyBin(bin))
    653653      bin = bin->next;
    654     else 
     654    else
    655655      bin = NULL;
    656656  }
     
    668668  else
    669669  {
    670     fprintf(fd, "%s%ld\t%ld\t", (omIsStaticNormalBin(bin) ? " " : 
    671                                 (omIsStickyBin(bin) ? "S" : 
     670    fprintf(fd, "%s%ld\t%ld\t", (omIsStaticNormalBin(bin) ? " " :
     671                                (omIsStickyBin(bin) ? "S" :
    672672                                 (omIsTrackBin(bin) ? "T" : "*"))),
    673673            bin->sizeW, bin->max_blocks);
     
    681681    {
    682682      omGetBinStat(bin, &s_pages, &s_used_blocks, &s_free_blocks);
    683       fprintf(fd, " \t \t%d\t%d\t%d\t%d\n", s_pages, s_free_blocks, s_used_blocks, 
     683      fprintf(fd, " \t \t%d\t%d\t%d\t%d\n", s_pages, s_free_blocks, s_used_blocks,
    684684              (int) bin->sticky);
    685685      bin = bin->next;
     
    690690  }
    691691}
    692  
     692
    693693void omPrintBinStats(FILE* fd)
    694694{
     
    697697  omSpecBin s_bin = om_SpecBin;
    698698  omBin sticky;
    699  
     699
    700700  fprintf(fd, " SizeW\tBlocks\tUPages\tFBlocks\tUBlocks\tSticky\n");
    701701  fflush(fd);
     
    709709       free_blocks += free_blocks_p;
    710710#ifdef OM_HAVE_TRACK
    711        if (om_StaticTrackBin[i].current_page != om_ZeroPage) 
     711       if (om_StaticTrackBin[i].current_page != om_ZeroPage)
    712712       {
    713713         omPrintBinStat(fd, &om_StaticTrackBin[i], 1, &pages_p, &used_blocks_p, &free_blocks_p);
     
    716716         free_blocks += free_blocks_p;
    717717       }
    718 #endif       
     718#endif
    719719       i--;
    720720    }
     
    751751  fprintf(fd, "      \t      \t%d\t%d\t%d\n", pages, free_blocks, used_blocks);
    752752}
    753  
     753
    754754static  int omGetUsedBytesOfBin(omBin bin)
    755755{
     
    765765  size_t used = 0;
    766766  omBin sticky;
    767  
     767
    768768  for (; i>=0; i--)
    769769  {
     
    796796  return used;
    797797}
    798 
Note: See TracChangeset for help on using the changeset viewer.