Changeset 13fe1b in git for omalloc/omBin.c
- Timestamp:
- Apr 30, 2001, 11:02:15 AM (23 years ago)
- Branches:
- (u'spielwiese', '2a584933abf2a2d3082034c7586d38bb6de1a30a')
- Children:
- 4d59e4136d84df15b329a224051e410d9f7ac557
- Parents:
- 38f6b334b77a57a06e357ad3a927916497dcb9bf
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
omalloc/omBin.c
r38f6b33 r13fe1b 4 4 * Author: obachman (Olaf Bachmann) 5 5 * Created: 11/99 6 * Version: $Id: omBin.c,v 1. 6 2000-12-12 15:26:15 obachmanExp $6 * Version: $Id: omBin.c,v 1.7 2001-04-30 09:02:02 Singular Exp $ 7 7 *******************************************************************/ 8 8 … … 40 40 #else 41 41 align = 0; 42 #endif 43 42 #endif 43 44 44 if (size > SIZEOF_OM_BIN_PAGE) 45 45 { 46 46 /* need page header */ 47 max_blocks = - (long) 47 max_blocks = - (long) 48 48 ((size+(SIZEOF_SYSTEM_PAGE-SIZEOF_OM_BIN_PAGE))+SIZEOF_SYSTEM_PAGE-1) 49 49 / SIZEOF_SYSTEM_PAGE; 50 sizeW = ((-max_blocks*SIZEOF_SYSTEM_PAGE) - 50 sizeW = ((-max_blocks*SIZEOF_SYSTEM_PAGE) - 51 51 (SIZEOF_SYSTEM_PAGE - SIZEOF_OM_BIN_PAGE)) / SIZEOF_LONG; 52 52 om_new_specBin = om_LargeBin; … … 64 64 #endif 65 65 sizeW = ((size + sizeW) & ~ (SIZEOF_OM_ALIGNMENT - 1)); 66 66 67 67 omAssume(sizeW >= size); 68 68 omAssume(max_blocks*sizeW <= SIZEOF_OM_BIN_PAGE); … … 87 87 } 88 88 #endif 89 else 89 else 90 90 { 91 91 om_new_specBin = omSmallSize2Bin( size ); … … 104 104 s_bin = omFindInSortedGList(om_SpecBin, next, max_blocks, max_blocks); 105 105 106 if (s_bin != NULL) 106 if (s_bin != NULL) 107 107 { 108 108 (s_bin->ref)++; 109 omAssume(s_bin->bin != NULL && 109 omAssume(s_bin->bin != NULL && 110 110 s_bin->bin->max_blocks == s_bin->max_blocks && 111 111 s_bin->bin->sizeW == sizeW); … … 144 144 if (! omIsStaticBin(bin)) 145 145 { 146 #ifdef OM_HAVE_TRACK 146 #ifdef OM_HAVE_TRACK 147 147 int track_bin = 0; 148 #endif 148 #endif 149 149 omSpecBin s_bin; 150 150 … … 156 156 #endif 157 157 s_bin = omFindInSortedGList(om_SpecBin, next, max_blocks, bin->max_blocks); 158 158 159 159 omAssume(s_bin != NULL && bin == s_bin->bin); 160 160 if (s_bin != NULL) … … 164 164 { 165 165 #ifdef OM_HAVE_TRACK 166 if (! track_bin) 166 if (! track_bin) 167 167 #endif 168 168 omFreeKeptAddrFromBin(s_bin->bin); … … 238 238 omBin s_bin; 239 239 s_bin = omGetStickyBin(bin, sticky_tag); 240 240 241 241 if (s_bin != bin) 242 242 { 243 243 omBinPage tc, tl; 244 244 unsigned long ts; 245 245 246 246 if (s_bin == NULL) s_bin = omCreateStickyBin(bin, sticky_tag); 247 247 ts = bin->sticky; … … 269 269 int length = omGListLength(to_bin->last_page, prev) + 270 270 omGListLength(from_bin->last_page, prev); 271 #endif 272 271 #endif 272 273 273 omBinPage page = from_bin->last_page; 274 274 omAssume(to_bin->sizeW == from_bin->sizeW); … … 291 291 return; 292 292 } 293 294 omAssume(to_bin->current_page != om_ZeroPage && 293 294 omAssume(to_bin->current_page != om_ZeroPage && 295 295 to_bin->current_page != NULL); 296 296 … … 309 309 { 310 310 /* 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 312 312 used_blocks != 0 && current == NULL */ 313 313 to_bin->current_page->used_blocks = 0; 314 314 } 315 316 317 omAssume(to_bin->current_page != NULL && 315 316 317 omAssume(to_bin->current_page != NULL && 318 318 to_bin->current_page->current == NULL && 319 319 to_bin->current_page->used_blocks == 0); 320 320 321 321 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) 323 323 to_bin->current_page->next->prev = from_bin->last_page; 324 324 else … … 330 330 page->prev = to_bin->current_page; 331 331 to_bin->current_page = from_bin->current_page; 332 332 333 333 #ifdef HAVE_OM_ASSUME 334 334 omAssume(omGListLength(to_bin->last_page, prev) == length); … … 346 346 return; 347 347 } 348 348 349 349 sticky_bin = omGetStickyBin(bin, sticky); 350 350 if (sticky_bin != NULL) … … 355 355 omMergeStickyPages(no_sticky_bin, sticky_bin); 356 356 357 if (bin == sticky_bin) 357 if (bin == sticky_bin) 358 358 { 359 359 sticky_bin = no_sticky_bin; … … 397 397 void omMergeStickyBinIntoBin(omBin sticky_bin, omBin into_bin) 398 398 { 399 if (! omIsOnGList(om_StickyBins, next, sticky_bin) || 399 if (! omIsOnGList(om_StickyBins, next, sticky_bin) || 400 400 !sticky_bin->sticky || 401 401 sticky_bin->max_blocks != into_bin->max_blocks || … … 405 405 { 406 406 #ifndef OM_NDEBUG 407 omReportError(omError_StickyBin, omError_NoError, OM_FLR, 407 omReportError(omError_StickyBin, omError_NoError, OM_FLR, 408 408 (! 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" : 410 410 (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" : 412 412 (!omIsKnownTopBin(into_bin, 1) ? "unknown into_bin" : 413 413 (omIsStickyBin(into_bin) ? "into_bin is sticky" : … … 430 430 #if defined(OM_INTERNAL_DEBUG) && !defined(OM_NDEBUG) 431 431 omTestBin(into_bin, 2); 432 #endif 433 } 434 432 #endif 433 } 434 435 435 /***************************************************************** 436 436 * … … 444 444 omSpecBin s_bin; 445 445 int i; 446 446 447 447 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) 451 451 { 452 452 to_check = om_StaticTrackBin; 453 453 s_bin = om_SpecTrackBin; 454 454 } 455 else 455 else 456 456 #endif 457 457 { … … 463 463 for (i=0; i<= OM_MAX_BIN_INDEX; i++) 464 464 { 465 if (bin == &(to_check[i])) 465 if (bin == &(to_check[i])) 466 466 return 1; 467 467 } 468 468 469 469 while (s_bin != NULL) 470 470 { … … 495 495 } 496 496 s_bin = om_SpecBin; 497 while (s_bin != NULL) 497 while (s_bin != NULL) 498 498 { 499 499 new_sticky = omGetMaxStickyBinTag(s_bin->bin); … … 501 501 s_bin = s_bin->next; 502 502 } 503 if (sticky < BIT_SIZEOF_LONG - 2) 503 if (sticky < BIT_SIZEOF_LONG - 2) 504 504 { 505 505 sticky++; … … 509 509 } 510 510 s_bin = om_SpecBin; 511 while (s_bin != NULL) 511 while (s_bin != NULL) 512 512 { 513 513 omCreateStickyBin(s_bin->bin, sticky); … … 527 527 } 528 528 s_bin = om_SpecBin; 529 while (s_bin != NULL) 529 while (s_bin != NULL) 530 530 { 531 531 if (omGetStickyBin(s_bin->bin, BIT_SIZEOF_LONG -1) == NULL) … … 545 545 omSetStickyBinTag(&(om_StaticBin[i]), sticky); 546 546 } 547 while (s_bin != NULL) 547 while (s_bin != NULL) 548 548 { 549 549 omSetStickyBinTag(s_bin->bin, sticky); … … 560 560 omUnSetStickyBinTag(&(om_StaticBin[i]), sticky); 561 561 } 562 while (s_bin != NULL) 562 while (s_bin != NULL) 563 563 { 564 564 omUnSetStickyBinTag(s_bin->bin, sticky); … … 575 575 omDeleteStickyBinTag(&(om_StaticBin[i]), sticky); 576 576 } 577 while (s_bin != NULL) 577 while (s_bin != NULL) 578 578 { 579 579 omDeleteStickyBinTag(s_bin->bin, sticky); … … 586 586 { 587 587 omBinPage page = bin->last_page; 588 588 589 589 while (page != NULL) 590 590 { 591 591 void* addr = (void*) page + SIZEOF_OM_BIN_PAGE_HEADER; 592 592 int i; 593 593 594 594 for (i=0; i<bin->max_blocks; i++) 595 595 { … … 608 608 * 609 609 *****************************************************************/ 610 static void omGetBinStat(omBin bin, int *pages_p, int *used_blocks_p, 610 static void omGetBinStat(omBin bin, int *pages_p, int *used_blocks_p, 611 611 int *free_blocks_p) 612 612 { 613 613 int pages = 0, used_blocks = 0, free_blocks = 0; 614 614 int where = 1; 615 615 616 616 omBinPage page = bin->last_page; 617 617 while (page != NULL) 618 618 { 619 pages++; if (where == 1) 619 pages++; if (where == 1) 620 620 { 621 621 used_blocks += omGetUsedBlocksOfPage(page) + 1; … … 623 623 free_blocks += bin->max_blocks - omGetUsedBlocksOfPage(page) -1; 624 624 } 625 else 625 else 626 626 { 627 627 if (bin->max_blocks > 1) … … 638 638 } 639 639 640 static void omGetTotalBinStat(omBin bin, int *pages_p, int *used_blocks_p, 640 static void omGetTotalBinStat(omBin bin, int *pages_p, int *used_blocks_p, 641 641 int *free_blocks_p) 642 642 { 643 643 int t_pages = 0, t_used_blocks = 0, t_free_blocks = 0; 644 644 int pages = 0, used_blocks = 0, free_blocks = 0; 645 645 646 646 while (bin != NULL) 647 647 { … … 652 652 if (!omIsStickyBin(bin)) 653 653 bin = bin->next; 654 else 654 else 655 655 bin = NULL; 656 656 } … … 668 668 else 669 669 { 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" : 672 672 (omIsTrackBin(bin) ? "T" : "*"))), 673 673 bin->sizeW, bin->max_blocks); … … 681 681 { 682 682 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, 684 684 (int) bin->sticky); 685 685 bin = bin->next; … … 690 690 } 691 691 } 692 692 693 693 void omPrintBinStats(FILE* fd) 694 694 { … … 697 697 omSpecBin s_bin = om_SpecBin; 698 698 omBin sticky; 699 699 700 700 fprintf(fd, " SizeW\tBlocks\tUPages\tFBlocks\tUBlocks\tSticky\n"); 701 701 fflush(fd); … … 709 709 free_blocks += free_blocks_p; 710 710 #ifdef OM_HAVE_TRACK 711 if (om_StaticTrackBin[i].current_page != om_ZeroPage) 711 if (om_StaticTrackBin[i].current_page != om_ZeroPage) 712 712 { 713 713 omPrintBinStat(fd, &om_StaticTrackBin[i], 1, &pages_p, &used_blocks_p, &free_blocks_p); … … 716 716 free_blocks += free_blocks_p; 717 717 } 718 #endif 718 #endif 719 719 i--; 720 720 } … … 751 751 fprintf(fd, " \t \t%d\t%d\t%d\n", pages, free_blocks, used_blocks); 752 752 } 753 753 754 754 static int omGetUsedBytesOfBin(omBin bin) 755 755 { … … 765 765 size_t used = 0; 766 766 omBin sticky; 767 767 768 768 for (; i>=0; i--) 769 769 { … … 796 796 return used; 797 797 } 798
Note: See TracChangeset
for help on using the changeset viewer.