My Project
Loading...
Searching...
No Matches
Macros | Functions | Variables
omBin.c File Reference
#include "omalloc.h"

Go to the source code of this file.

Macros

#define om_LargeBin   ((omBin) 1)
 
#define omGetStickyBin(bin, sticky_tag)    omFindInGList(bin, next, sticky, sticky_tag)
 

Functions

omBin _omGetSpecBin (size_t size, int align, int track)
 
void _omUnGetSpecBin (omBin *bin_p, int force)
 
static omBin omCreateStickyBin (omBin bin, unsigned long sticky)
 
unsigned long omGetMaxStickyBinTag (omBin bin)
 
unsigned long omGetNewStickyBinTag (omBin bin)
 
void omSetStickyBinTag (omBin bin, unsigned long sticky_tag)
 
void omUnSetStickyBinTag (omBin bin, unsigned long sticky)
 
static void omMergeStickyPages (omBin to_bin, omBin from_bin)
 
void omDeleteStickyBinTag (omBin bin, unsigned long sticky)
 
omBin omGetStickyBinOfBin (omBin bin)
 
void omMergeStickyBinIntoBin (omBin sticky_bin, omBin into_bin)
 
int omIsKnownTopBin (omBin bin, int normal_bin)
 
unsigned long omGetNewStickyAllBinTag ()
 
void omSetStickyAllBinTag (unsigned long sticky)
 
void omUnSetStickyAllBinTag (unsigned long sticky)
 
void omDeleteStickyAllBinTag (unsigned long sticky)
 
static void omGetBinStat (omBin bin, long *pages_p, long *used_blocks_p, long *free_blocks_p)
 
static void omGetTotalBinStat (omBin bin, long *pages_p, long *used_blocks_p, long *free_blocks_p)
 
static void omPrintBinStat (FILE *fd, omBin bin, int track, long *pages, long *used_blocks, long *free_blocks)
 
void omPrintBinStats (FILE *fd)
 
static long omGetUsedBytesOfBin (omBin bin)
 
long omGetUsedBinBytes ()
 

Variables

omBin om_StickyBins = NULL
 

Macro Definition Documentation

◆ om_LargeBin

#define om_LargeBin   ((omBin) 1)

Definition at line 25 of file omBin.c.

◆ omGetStickyBin

#define omGetStickyBin (   bin,
  sticky_tag 
)     omFindInGList(bin, next, sticky, sticky_tag)

Definition at line 193 of file omBin.c.

196{
197 omBin s_bin = (omBin) omAlloc(sizeof(omBin_t));
198 s_bin->sticky = sticky;
199 s_bin->current_page = om_ZeroPage;
200 s_bin->last_page = NULL;
201 s_bin->max_blocks = bin->max_blocks;
202 s_bin->sizeW = bin->sizeW;
203 s_bin->next = bin->next;
204 bin->next = s_bin;
205 return s_bin;
206}
207
208unsigned long omGetMaxStickyBinTag(omBin bin)
209{
210 unsigned long sticky = 0;
211 do
212 {
213 if (bin->sticky > sticky) sticky = bin->sticky;
214 bin = bin->next;
215 }
216 while (bin != NULL);
217 return sticky;
218}
219
220unsigned long omGetNewStickyBinTag(omBin bin)
221{
222 unsigned long sticky = omGetMaxStickyBinTag(bin);
223 if (sticky < BIT_SIZEOF_LONG - 2)
224 {
225 sticky++;
226 omCreateStickyBin(bin, sticky);
227 return sticky;
228 }
229 else
230 {
231 omAssume(sticky == BIT_SIZEOF_LONG - 1);
232 }
233 return sticky;
234}
235
236void omSetStickyBinTag(omBin bin, unsigned long sticky_tag)
237{
238 omBin s_bin;
240
241 if (s_bin != bin)
242 {
243 omBinPage tc, tl;
244 unsigned long ts;
245
247 ts = bin->sticky;
248 tl = bin->last_page;
249 tc = bin->current_page;
250 bin->sticky = s_bin->sticky;
251 bin->current_page = s_bin->current_page;
252 bin->last_page = s_bin->last_page;
253 s_bin->sticky = ts;
254 s_bin->last_page = tl;
255 s_bin->current_page = tc;
256 }
257}
258
259void omUnSetStickyBinTag(omBin bin, unsigned long sticky)
260{
261 omAssume(omGetStickyBin(bin, 0) != NULL);
262 if (bin->sticky == sticky)
263 omSetStickyBinTag(bin, 0);
264}
265
267{
268#ifdef HAVE_OM_ASSUME
269 int length = omGListLength(to_bin->last_page, prev) +
270 omGListLength(from_bin->last_page, prev);
271#endif
272
273 omBinPage page = from_bin->last_page;
274 omAssume(to_bin->sizeW == from_bin->sizeW);
276
277 if (page == NULL) return;
278 do
279 {
281 if (page->prev == NULL) break;
282 page = page->prev;
283 }
284 while(1);
285
286 if (to_bin->last_page == NULL)
287 {
288 omAssume(to_bin->current_page == om_ZeroPage);
289 to_bin->last_page = from_bin->last_page;
290 to_bin->current_page = from_bin->current_page;
291 return;
292 }
293
294 omAssume(to_bin->current_page != om_ZeroPage &&
295 to_bin->current_page != NULL);
296
297 if (to_bin->current_page->current != NULL)
298 {
299 if (to_bin->current_page->prev == NULL)
300 {
301 from_bin->last_page->next = to_bin->current_page;
302 to_bin->current_page->prev = from_bin->last_page;
303 to_bin->current_page = from_bin->current_page;
304 return;
305 }
306 to_bin->current_page = to_bin->current_page->prev;
307 }
308 else
309 {
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
312 used_blocks != 0 && current == NULL */
313 to_bin->current_page->used_blocks = 0;
314 }
315
316
317 omAssume(to_bin->current_page != NULL &&
318 to_bin->current_page->current == NULL &&
319 to_bin->current_page->used_blocks == 0);
320
321 from_bin->last_page->next = to_bin->current_page->next;
322 if (to_bin->current_page->next != NULL)
323 to_bin->current_page->next->prev = from_bin->last_page;
324 else
325 {
326 omAssume(to_bin->current_page == to_bin->last_page);
327 to_bin->last_page = from_bin->last_page;
328 }
329 to_bin->current_page->next = page;
330 page->prev = to_bin->current_page;
331 to_bin->current_page = from_bin->current_page;
332
333#ifdef HAVE_OM_ASSUME
334 omAssume(omGListLength(to_bin->last_page, prev) == length);
335#endif
336}
337
338void omDeleteStickyBinTag(omBin bin, unsigned long sticky)
339{
342
343 if (sticky == 0)
344 {
345 omAssume(0);
346 return;
347 }
348
349 sticky_bin = omGetStickyBin(bin, sticky);
350 if (sticky_bin != NULL)
351 {
354
356
357 if (bin == sticky_bin)
358 {
360 omSetStickyBinTag(bin, 0);
361 }
362 bin->next = omRemoveFromGList(bin->next, next, sticky_bin);
363 omFreeSize(sticky_bin, sizeof(omBin_t));
364 }
365}
366
367
368/*****************************************************************
369 *
370 * Sticky bins
371 *
372 *****************************************************************/
375{
376 omBin new_bin = omAlloc(sizeof(omBin_t));
377 omAssume(omIsKnownTopBin(bin, 1) && ! omIsStickyBin(bin));
378 new_bin->sticky = SIZEOF_VOIDP;
379 new_bin->max_blocks = bin->max_blocks;
380 new_bin->sizeW = bin->sizeW;
381 new_bin->next = om_StickyBins;
383 new_bin->last_page = NULL;
384 new_bin->current_page = om_ZeroPage;
385#if 0
386 if (omIsSpecBin(bin))
387 {
388 omSpecBin s_bin = omFindInSortedGList(om_SpecBin, next, max_blocks, bin->max_blocks);
389 omAssume(s_bin != NULL);
390 if (s_bin != NULL)
391 s_bin->ref++;
392 }
393#endif
394 return new_bin;
395}
396
398{
400 !sticky_bin->sticky ||
401 sticky_bin->max_blocks != into_bin->max_blocks ||
402 sticky_bin == into_bin ||
405 {
406#ifndef OM_NDEBUG
408 (! omIsOnGList(om_StickyBins, next, sticky_bin) ? "unknown sticky_bin" :
409 (!sticky_bin->sticky ? "sticky_bin is not sticky" :
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" :
412 (!omIsKnownTopBin(into_bin, 1) ? "unknown into_bin" :
413 (omIsStickyBin(into_bin) ? "into_bin is sticky" :
414 "unknown sticky_bin error")))))));
415#endif
416 return;
417 }
421
422#if 0
423 if (! omIsStaticBin(into_bin))
424 {
427 }
428#endif
429 omFreeSize(sticky_bin, sizeof(omBin_t));
430#if defined(OM_INTERNAL_DEBUG) && !defined(OM_NDEBUG)
432#endif
433}
434
435/*****************************************************************
436*
437* AllBin business
438*
439*****************************************************************/
440#ifndef OM_NDEBUG
441int omIsKnownTopBin(omBin bin, int normal_bin)
442{
445 int i;
446
447 omAssume(normal_bin == 1 || normal_bin == 0);
448
449#ifdef OM_HAVE_TRACK
450 if (! normal_bin)
451 {
454 }
455 else
456#endif
457 {
461 }
462
463 for (i=0; i<= OM_MAX_BIN_INDEX; i++)
464 {
465 if (bin == &(to_check[i]))
466 return 1;
467 }
468
469 while (s_bin != NULL)
470 {
471 if (bin == s_bin->bin) return 1;
472 s_bin = s_bin->next;
473 }
475
476 while (to_check != NULL)
477 {
478 if (bin == to_check) return 1;
479 to_check = to_check->next;
480 }
481 return 0;
482}
483#endif
484
485unsigned long omGetNewStickyAllBinTag()
486{
487 unsigned long sticky = 0, new_sticky;
488 int i;
490 // first, find new sticky tag
491 for (i=0; i<=OM_MAX_BIN_INDEX; i++)
492 {
494 if (new_sticky > sticky) sticky = new_sticky;
495 }
497 while (s_bin != NULL)
498 {
500 if (new_sticky > sticky) sticky = new_sticky;
501 s_bin = s_bin->next;
502 }
503 if (sticky < BIT_SIZEOF_LONG - 2)
504 {
505 sticky++;
506 for (i=0; i<=OM_MAX_BIN_INDEX; i++)
507 {
508 omCreateStickyBin(&(om_StaticBin[i]), sticky);
509 }
511 while (s_bin != NULL)
512 {
513 omCreateStickyBin(s_bin->bin, sticky);
514 s_bin = s_bin->next;
515 }
516 return sticky;
517 }
518 else
519 {
520 omBin bin;
521 omAssume(sticky == BIT_SIZEOF_LONG - 1);
522 for (i=0; i<=OM_MAX_BIN_INDEX; i++)
523 {
524 bin = &om_StaticBin[i];
525 if (omGetStickyBin(bin, BIT_SIZEOF_LONG -1) == NULL)
527 }
529 while (s_bin != NULL)
530 {
531 if (omGetStickyBin(s_bin->bin, BIT_SIZEOF_LONG -1) == NULL)
533 s_bin = s_bin->next;
534 }
535 return BIT_SIZEOF_LONG - 1;
536 }
537}
538
539void omSetStickyAllBinTag(unsigned long sticky)
540{
542 int i;
543 for (i=0; i<=OM_MAX_BIN_INDEX; i++)
544 {
545 omSetStickyBinTag(&(om_StaticBin[i]), sticky);
546 }
547 while (s_bin != NULL)
548 {
549 omSetStickyBinTag(s_bin->bin, sticky);
550 s_bin = s_bin->next;
551 }
552}
553
554void omUnSetStickyAllBinTag(unsigned long sticky)
555{
557 int i;
558 for (i=0; i<=OM_MAX_BIN_INDEX; i++)
559 {
561 }
562 while (s_bin != NULL)
563 {
564 omUnSetStickyBinTag(s_bin->bin, sticky);
565 s_bin = s_bin->next;
566 }
567}
568
569void omDeleteStickyAllBinTag(unsigned long sticky)
570{
572 int i;
573 for (i=0; i<=OM_MAX_BIN_INDEX; i++)
574 {
576 }
577 while (s_bin != NULL)
578 {
579 omDeleteStickyBinTag(s_bin->bin, sticky);
580 s_bin = s_bin->next;
581 }
582}
583
584#if 0
585void omPrintMissing(omBin bin)
586{
587 omBinPage page = bin->last_page;
588
589 while (page != NULL)
590 {
591 void* addr = (void*) page + SIZEOF_OM_BIN_PAGE_HEADER;
592 int i;
593
594 for (i=0; i<bin->max_blocks; i++)
595 {
596 if (! omIsOnList(page->current, addr))
597 printf("%d:%p\n", i, addr);
598 addr += bin->sizeW*SIZEOF_LONG;
599 }
600 page = page->prev;
601 }
602}
603#endif
604
605/*****************************************************************
606 *
607 * Statistics
608 *
609 *****************************************************************/
610static void omGetBinStat(omBin bin, long *pages_p, long *used_blocks_p,
611 long *free_blocks_p)
612{
613 long pages = 0, used_blocks = 0, free_blocks = 0;
614 int where = 1;
615
616 omBinPage page = bin->last_page;
617 while (page != NULL)
618 {
619 pages++; if (where == 1)
620 {
621 used_blocks += omGetUsedBlocksOfPage(page) + 1;
622 if (bin->max_blocks > 0)
623 free_blocks += bin->max_blocks - omGetUsedBlocksOfPage(page) -1;
624 }
625 else
626 {
627 if (bin->max_blocks > 1)
628 used_blocks += bin->max_blocks;
629 else
630 used_blocks++;
631 }
632 if (page == bin->current_page) where = -1;
633 page = page->prev;
634 }
635 *pages_p = pages;
636 *used_blocks_p = used_blocks;
638}
639
640static void omGetTotalBinStat(omBin bin, long *pages_p, long *used_blocks_p,
641 long *free_blocks_p)
642{
643 long t_pages = 0, t_used_blocks = 0, t_free_blocks = 0;
644 long pages = 0, used_blocks = 0, free_blocks = 0;
645
646 while (bin != NULL)
647 {
648 omGetBinStat(bin, &pages, &used_blocks, &free_blocks);
649 t_pages += pages;
650 t_used_blocks += used_blocks;
652 if (!omIsStickyBin(bin))
653 bin = bin->next;
654 else
655 bin = NULL;
656 }
657 *pages_p = t_pages;
660}
661
662static void omPrintBinStat(FILE * fd, omBin bin, int track, long* pages, long* used_blocks, long* free_blocks)
663{
664 if (track)
665 {
666 fputs("T \t \t",fd);
667 }
668 else
669 {
670 fprintf(fd, "%s%ld\t%ld\t", (omIsStaticNormalBin(bin) ? " " :
671 (omIsStickyBin(bin) ? "S" :
672 (omIsTrackBin(bin) ? "T" : "*"))),
673 (long)bin->sizeW, bin->max_blocks);
674 }
675 omGetTotalBinStat(bin, pages, used_blocks, free_blocks);
676 fprintf(fd, "%ld\t%ld\t%ld\n", *pages, *free_blocks, *used_blocks);
677 if (bin->next != NULL && !omIsStickyBin(bin))
678 {
680 while (bin != NULL)
681 {
683 fprintf(fd, " \t \t%ld\t%ld\t%ld\t%d\n", s_pages, s_free_blocks, s_used_blocks,
684 (int) bin->sticky);
685 bin = bin->next;
686 *pages += s_pages;
687 *used_blocks += s_used_blocks;
689 }
690 }
691}
692
694{
695 int i = OM_MAX_BIN_INDEX;
696 long pages=0, used_blocks=0, free_blocks=0;
699 omBin sticky;
700
701 fputs(" SizeW\tBlocks\tUPages\tFBlocks\tUBlocks\tSticky\n",fd);
702 fflush(fd);
703 while (s_bin != NULL || i >= 0)
704 {
705 if (s_bin == NULL || (i >= 0 && (unsigned long) om_StaticBin[i].max_blocks < (unsigned long) s_bin->bin->max_blocks))
706 {
708 pages += pages_p;
709 used_blocks += used_blocks_p;
711#ifdef OM_HAVE_TRACK
712 if (om_StaticTrackBin[i].current_page != om_ZeroPage)
713 {
715 pages += pages_p;
716 used_blocks += used_blocks_p;
718 }
719#endif
720 i--;
721 }
722 else
723 {
725 pages += pages_p;
726 used_blocks += used_blocks_p;
728 s_bin = s_bin->next;
729 }
730 }
731#ifdef OM_HAVE_TRACK
733 while (s_bin != NULL)
734 {
736 s_bin = s_bin->next;
737 pages += pages_p;
738 used_blocks += used_blocks_p;
740 }
741#endif
742 sticky = om_StickyBins;
743 while (sticky != NULL)
744 {
746 sticky = sticky->next;
747 pages += pages_p;
748 used_blocks += used_blocks_p;
750 }
751 fputs("----------------------------------------\n",fd);
752 fprintf(fd, " \t \t%ld\t%ld\t%ld\n", pages, free_blocks, used_blocks);
753}
754
755static long omGetUsedBytesOfBin(omBin bin)
756{
757 long pages = 0, used_blocks = 0, free_blocks = 0;
758 omGetTotalBinStat(bin, &pages, &used_blocks, &free_blocks);
759 return (used_blocks)*((long)bin->sizeW)*SIZEOF_LONG;
760}
761
763{
764 int i = OM_MAX_BIN_INDEX;
766 long used = 0;
767 omBin sticky;
768
769 for (; i>=0; i--)
770 {
772 }
773 while (s_bin != NULL)
774 {
776 s_bin = s_bin->next;
777 }
778#ifdef OM_HAVE_TRACK
779 for (i=OM_MAX_BIN_INDEX; i>=0; i--)
780 {
782 }
784 while (s_bin != NULL)
785 {
787 s_bin = s_bin->next;
788 }
789#endif
790
791 sticky = om_StickyBins;
792 while (sticky != NULL)
793 {
794 used += omGetUsedBytesOfBin(sticky);
795 sticky = sticky->next;
796 }
797 return used;
798}
799#endif
#define BIT_SIZEOF_LONG
Definition auxiliary.h:80
int i
Definition cfEzgcd.cc:132
static BOOLEAN length(leftv result, leftv arg)
Definition interval.cc:257
ListNode * next
Definition janet.h:31
omError_t omTestBin(omBin bin, int check_level)
Definition omDebug.c:90
#define omFreeSize(addr, size)
#define omAlloc(size)
#define omSetTopBinAndStickyOfPage(page, bin, sticky)
#define SIZEOF_OM_BIN_PAGE_HEADER
omBin_t om_StaticBin[]
void omSetStickyBinTag(omBin bin, unsigned long sticky_tag)
Definition omBin.c:237
static void omPrintBinStat(FILE *fd, omBin bin, int track, long *pages, long *used_blocks, long *free_blocks)
Definition omBin.c:663
void omDeleteStickyBinTag(omBin bin, unsigned long sticky)
Definition omBin.c:339
void omSetStickyAllBinTag(unsigned long sticky)
Definition omBin.c:540
unsigned long omGetMaxStickyBinTag(omBin bin)
Definition omBin.c:209
static void omMergeStickyPages(omBin to_bin, omBin from_bin)
Definition omBin.c:267
long omGetUsedBinBytes()
Definition omBin.c:763
#define omGetStickyBin(bin, sticky_tag)
Definition omBin.c:193
static void omGetBinStat(omBin bin, long *pages_p, long *used_blocks_p, long *free_blocks_p)
Definition omBin.c:611
static void omGetTotalBinStat(omBin bin, long *pages_p, long *used_blocks_p, long *free_blocks_p)
Definition omBin.c:641
omBin om_StickyBins
Definition omBin.c:374
unsigned long omGetNewStickyBinTag(omBin bin)
Definition omBin.c:221
static omBin omCreateStickyBin(omBin bin, unsigned long sticky)
Definition omBin.c:196
void omDeleteStickyAllBinTag(unsigned long sticky)
Definition omBin.c:570
void omUnSetStickyBinTag(omBin bin, unsigned long sticky)
Definition omBin.c:260
void omUnSetStickyAllBinTag(unsigned long sticky)
Definition omBin.c:555
unsigned long omGetNewStickyAllBinTag()
Definition omBin.c:486
static long omGetUsedBytesOfBin(omBin bin)
Definition omBin.c:756
#define omIsKnownTopBin(bin, normal_bin)
Definition omBin.h:55
#define omIsStickyBin(bin)
Definition omBin.h:33
#define omIsStaticBin(bin)
Definition omBin.h:59
#define omIsSpecBin(bin)
Definition omBin.h:47
#define omIsStaticNormalBin(bin)
Definition omBin.h:43
#define omUnGetSpecBin(bin_ptr)
Definition omBin.h:14
#define omIsTrackBin(bin)
Definition omBin.h:57
void omFreeKeptAddrFromBin(omBin bin)
Definition omDebug.c:542
#define omGetUsedBlocksOfPage(page)
Definition omDebug.h:88
omError_t omReportError(omError_t error, omError_t report_error, OM_FLR_DECL, const char *fmt,...)
Definition omError.c:80
#define omAssume(x)
Definition omError.h:85
@ omError_NoError
Definition omError.h:18
@ omError_StickyBin
Definition omError.h:41
#define NULL
Definition omList.c:12
#define omIsOnList(ptr, addr)
Definition omList.h:68
#define omRemoveFromGList(ptr, next, addr)
Definition omList.h:102
#define omGListLength(ptr, next)
Definition omList.h:94
#define omIsOnGList(ptr, next, addr)
Definition omList.h:100
#define omFindInSortedGList(ptr, next, what, value)
Definition omList.h:108
omBinPage_t * omBinPage
Definition omStructs.h:16
omBin_t * omBin
Definition omStructs.h:12
#define OM_MAX_BIN_INDEX
Definition omTables.h:4
omBinPage_t om_ZeroPage[]
Definition om_Alloc.c:19
omSpecBin om_SpecBin
Definition om_Alloc.c:20
int status int fd
Definition si_signals.h:69
#define omGetStickyBinOfBin(B)
Definition xalloc.h:247
#define omMergeStickyBinIntoBin(A, B)
Definition xalloc.h:275
#define omPrintBinStats(F)
Definition xalloc.h:233

Function Documentation

◆ _omGetSpecBin()

omBin _omGetSpecBin ( size_t  size,
int  align,
int  track 
)

Definition at line 26 of file omBin.c.

28{
30 long max_blocks;
31 long sizeW;
32
33
35#ifdef OM_ALIGNMENT_NEEDS_WORK
37 {
38 align = 1;
40 }
41#else
42 align = 0;
43#endif
44
46 {
47 /* need page header */
48 max_blocks = - (long)
51 sizeW = ((-max_blocks*SIZEOF_SYSTEM_PAGE) -
54 }
55 else
56 {
57 /* SIZEOF_OM_BIN_PAGE == max_blocks*size + r1; r1 < size */
58 /* r1 = max_blocks*(size_padding) + r2; r2 < max_blocks */
59 max_blocks = SIZEOF_OM_BIN_PAGE / size;
60 sizeW = (SIZEOF_OM_BIN_PAGE % size) / max_blocks;
61#ifdef OM_ALIGNMENT_NEEDS_WORK
62 if (align)
63 sizeW = ((size + sizeW) & ~ (SIZEOF_STRICT_ALIGNMENT - 1));
64 else
65#endif
66 sizeW = ((size + sizeW) & ~ (SIZEOF_OM_ALIGNMENT - 1));
67
68 omAssume(sizeW >= size);
69 omAssume(max_blocks*sizeW <= SIZEOF_OM_BIN_PAGE);
70 omAssume((max_blocks+1)*sizeW > SIZEOF_OM_BIN_PAGE ||
71 max_blocks*(sizeW + SIZEOF_STRICT_ALIGNMENT) > SIZEOF_OM_BIN_PAGE);
72
73 sizeW = sizeW >> LOG_SIZEOF_LONG;
75 {
77 }
78#ifdef OM_ALIGNMENT_NEEDS_WORK
79 else if (align)
80 {
82 }
83#endif
84#ifdef OM_HAVE_TRACK
85 else if (track)
86 {
88 }
89#endif
90 else
91 {
93 }
94 }
95
97 om_new_specBin->max_blocks < max_blocks)
98 {
100#ifdef OM_HAVE_TRACK
101 if (track)
102 s_bin = omFindInSortedGList(om_SpecTrackBin, next, max_blocks, max_blocks);
103 else
104#endif
105 s_bin = omFindInSortedGList(om_SpecBin, next, max_blocks, max_blocks);
106
107 if (s_bin != NULL)
108 {
109 (s_bin->ref)++;
110 omAssume(s_bin->bin != NULL &&
111 s_bin->bin->max_blocks == s_bin->max_blocks &&
112 s_bin->bin->sizeW == sizeW);
113 return s_bin->bin;
114 }
115 s_bin = (omSpecBin) omAlloc(sizeof(omSpecBin_t));
116 s_bin->ref = 1;
117 s_bin->next = NULL;
118 s_bin->max_blocks = max_blocks;
119 s_bin->bin = (omBin) omAlloc(sizeof(omBin_t));
120 s_bin->bin->current_page = om_ZeroPage;
121 s_bin->bin->last_page = NULL;
122 s_bin->bin->next = NULL;
123 s_bin->bin->sizeW = sizeW;
124 s_bin->bin->max_blocks = max_blocks;
125 s_bin->bin->sticky = 0;
126#ifdef OM_HAVE_TRACK
127 if (track)
128 {
130 }
131 else
132#endif
134 return s_bin->bin;
135 }
136 else
137 {
138 return om_new_specBin;
139 }
140}
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition cf_ops.cc:600
#define SIZEOF_OM_BIN_PAGE
#define omSmallSize2Bin(size)
#define om_LargeBin
Definition omBin.c:25
#define omInsertInSortedGList(ptr, next, what, addr)
Definition omList.h:106
omSpecBin_t * omSpecBin
Definition omStructs.h:30
#define OM_MAX_BLOCK_SIZE
Definition omTables.c:31
#define OM_SIZEOF_UNIQUE_MAX_BLOCK_THRESHOLD
Definition omTables.h:5
#define omSmallSize2AlignedBin

◆ _omUnGetSpecBin()

void _omUnGetSpecBin ( omBin bin_p,
int  force 
)

Definition at line 142 of file omBin.c.

143{
144 omBin bin = *bin_p;
145 if (! omIsStaticBin(bin))
146 {
147#ifdef OM_HAVE_TRACK
148 int track_bin = 0;
149#endif
151
152#ifdef OM_HAVE_TRACK
154 if (s_bin != NULL)
155 track_bin = 1;
156 else
157#endif
158 s_bin = omFindInSortedGList(om_SpecBin, next, max_blocks, bin->max_blocks);
159
160 omAssume(s_bin != NULL && bin == s_bin->bin);
161 if (s_bin != NULL)
162 {
163 (s_bin->ref)--;
164 if (s_bin->ref == 0 || force)
165 {
166#ifdef OM_HAVE_TRACK
167 if (! track_bin)
168#endif
170 if(s_bin->bin->last_page == NULL || force)
171 {
172#ifdef OM_HAVE_TRACK
173 if (track_bin)
175 else
176#endif
178 omFreeSize(s_bin->bin, sizeof(omBin_t));
179 omFreeSize(s_bin, sizeof(omSpecBin_t));
180 }
181 }
182 }
183 }
184 *bin_p = NULL;
185}
#define omFindInGList(ptr, next, what, value)
Definition omList.h:104
#define omRemoveFromSortedGList(ptr, next, what, addr)
Definition omList.h:110

◆ omCreateStickyBin()

static omBin omCreateStickyBin ( omBin  bin,
unsigned long  sticky 
)
static

Definition at line 196 of file omBin.c.

197{
198 omBin s_bin = (omBin) omAlloc(sizeof(omBin_t));
199 s_bin->sticky = sticky;
200 s_bin->current_page = om_ZeroPage;
201 s_bin->last_page = NULL;
202 s_bin->max_blocks = bin->max_blocks;
203 s_bin->sizeW = bin->sizeW;
204 s_bin->next = bin->next;
205 bin->next = s_bin;
206 return s_bin;
207}

◆ omDeleteStickyAllBinTag()

void omDeleteStickyAllBinTag ( unsigned long  sticky)

Definition at line 570 of file omBin.c.

571{
573 int i;
574 for (i=0; i<=OM_MAX_BIN_INDEX; i++)
575 {
577 }
578 while (s_bin != NULL)
579 {
580 omDeleteStickyBinTag(s_bin->bin, sticky);
581 s_bin = s_bin->next;
582 }
583}

◆ omDeleteStickyBinTag()

void omDeleteStickyBinTag ( omBin  bin,
unsigned long  sticky 
)

Definition at line 339 of file omBin.c.

340{
343
344 if (sticky == 0)
345 {
346 omAssume(0);
347 return;
348 }
349
350 sticky_bin = omGetStickyBin(bin, sticky);
351 if (sticky_bin != NULL)
352 {
355
357
358 if (bin == sticky_bin)
359 {
361 omSetStickyBinTag(bin, 0);
362 }
363 bin->next = omRemoveFromGList(bin->next, next, sticky_bin);
364 omFreeSize(sticky_bin, sizeof(omBin_t));
365 }
366}

◆ omGetBinStat()

static void omGetBinStat ( omBin  bin,
long pages_p,
long used_blocks_p,
long free_blocks_p 
)
static

Definition at line 611 of file omBin.c.

613{
614 long pages = 0, used_blocks = 0, free_blocks = 0;
615 int where = 1;
616
617 omBinPage page = bin->last_page;
618 while (page != NULL)
619 {
620 pages++; if (where == 1)
621 {
622 used_blocks += omGetUsedBlocksOfPage(page) + 1;
623 if (bin->max_blocks > 0)
624 free_blocks += bin->max_blocks - omGetUsedBlocksOfPage(page) -1;
625 }
626 else
627 {
628 if (bin->max_blocks > 1)
629 used_blocks += bin->max_blocks;
630 else
631 used_blocks++;
632 }
633 if (page == bin->current_page) where = -1;
634 page = page->prev;
635 }
636 *pages_p = pages;
637 *used_blocks_p = used_blocks;
639}

◆ omGetMaxStickyBinTag()

unsigned long omGetMaxStickyBinTag ( omBin  bin)

Definition at line 209 of file omBin.c.

210{
211 unsigned long sticky = 0;
212 do
213 {
214 if (bin->sticky > sticky) sticky = bin->sticky;
215 bin = bin->next;
216 }
217 while (bin != NULL);
218 return sticky;
219}

◆ omGetNewStickyAllBinTag()

unsigned long omGetNewStickyAllBinTag ( void  )

Definition at line 486 of file omBin.c.

487{
488 unsigned long sticky = 0, new_sticky;
489 int i;
491 // first, find new sticky tag
492 for (i=0; i<=OM_MAX_BIN_INDEX; i++)
493 {
495 if (new_sticky > sticky) sticky = new_sticky;
496 }
498 while (s_bin != NULL)
499 {
501 if (new_sticky > sticky) sticky = new_sticky;
502 s_bin = s_bin->next;
503 }
504 if (sticky < BIT_SIZEOF_LONG - 2)
505 {
506 sticky++;
507 for (i=0; i<=OM_MAX_BIN_INDEX; i++)
508 {
509 omCreateStickyBin(&(om_StaticBin[i]), sticky);
510 }
512 while (s_bin != NULL)
513 {
514 omCreateStickyBin(s_bin->bin, sticky);
515 s_bin = s_bin->next;
516 }
517 return sticky;
518 }
519 else
520 {
521 omBin bin;
522 omAssume(sticky == BIT_SIZEOF_LONG - 1);
523 for (i=0; i<=OM_MAX_BIN_INDEX; i++)
524 {
525 bin = &om_StaticBin[i];
526 if (omGetStickyBin(bin, BIT_SIZEOF_LONG -1) == NULL)
528 }
530 while (s_bin != NULL)
531 {
532 if (omGetStickyBin(s_bin->bin, BIT_SIZEOF_LONG -1) == NULL)
534 s_bin = s_bin->next;
535 }
536 return BIT_SIZEOF_LONG - 1;
537 }
538}

◆ omGetNewStickyBinTag()

unsigned long omGetNewStickyBinTag ( omBin  bin)

Definition at line 221 of file omBin.c.

222{
223 unsigned long sticky = omGetMaxStickyBinTag(bin);
224 if (sticky < BIT_SIZEOF_LONG - 2)
225 {
226 sticky++;
227 omCreateStickyBin(bin, sticky);
228 return sticky;
229 }
230 else
231 {
232 omAssume(sticky == BIT_SIZEOF_LONG - 1);
233 }
234 return sticky;
235}

◆ omGetStickyBinOfBin()

omBin omGetStickyBinOfBin ( omBin  bin)

Definition at line 375 of file omBin.c.

376{
377 omBin new_bin = omAlloc(sizeof(omBin_t));
378 omAssume(omIsKnownTopBin(bin, 1) && ! omIsStickyBin(bin));
379 new_bin->sticky = SIZEOF_VOIDP;
380 new_bin->max_blocks = bin->max_blocks;
381 new_bin->sizeW = bin->sizeW;
382 new_bin->next = om_StickyBins;
384 new_bin->last_page = NULL;
385 new_bin->current_page = om_ZeroPage;
386#if 0
387 if (omIsSpecBin(bin))
388 {
389 omSpecBin s_bin = omFindInSortedGList(om_SpecBin, next, max_blocks, bin->max_blocks);
390 omAssume(s_bin != NULL);
391 if (s_bin != NULL)
392 s_bin->ref++;
393 }
394#endif
395 return new_bin;
396}

◆ omGetTotalBinStat()

static void omGetTotalBinStat ( omBin  bin,
long pages_p,
long used_blocks_p,
long free_blocks_p 
)
static

Definition at line 641 of file omBin.c.

643{
644 long t_pages = 0, t_used_blocks = 0, t_free_blocks = 0;
645 long pages = 0, used_blocks = 0, free_blocks = 0;
646
647 while (bin != NULL)
648 {
649 omGetBinStat(bin, &pages, &used_blocks, &free_blocks);
650 t_pages += pages;
651 t_used_blocks += used_blocks;
653 if (!omIsStickyBin(bin))
654 bin = bin->next;
655 else
656 bin = NULL;
657 }
658 *pages_p = t_pages;
661}

◆ omGetUsedBinBytes()

long omGetUsedBinBytes ( void  )

Definition at line 763 of file omBin.c.

764{
765 int i = OM_MAX_BIN_INDEX;
767 long used = 0;
768 omBin sticky;
769
770 for (; i>=0; i--)
771 {
773 }
774 while (s_bin != NULL)
775 {
777 s_bin = s_bin->next;
778 }
779#ifdef OM_HAVE_TRACK
780 for (i=OM_MAX_BIN_INDEX; i>=0; i--)
781 {
783 }
785 while (s_bin != NULL)
786 {
788 s_bin = s_bin->next;
789 }
790#endif
791
792 sticky = om_StickyBins;
793 while (sticky != NULL)
794 {
795 used += omGetUsedBytesOfBin(sticky);
796 sticky = sticky->next;
797 }
798 return used;
799}

◆ omGetUsedBytesOfBin()

static long omGetUsedBytesOfBin ( omBin  bin)
static

Definition at line 756 of file omBin.c.

757{
758 long pages = 0, used_blocks = 0, free_blocks = 0;
759 omGetTotalBinStat(bin, &pages, &used_blocks, &free_blocks);
760 return (used_blocks)*((long)bin->sizeW)*SIZEOF_LONG;
761}

◆ omIsKnownTopBin()

int omIsKnownTopBin ( omBin  bin,
int  normal_bin 
)

Definition at line 442 of file omBin.c.

443{
446 int i;
447
448 omAssume(normal_bin == 1 || normal_bin == 0);
449
450#ifdef OM_HAVE_TRACK
451 if (! normal_bin)
452 {
455 }
456 else
457#endif
458 {
462 }
463
464 for (i=0; i<= OM_MAX_BIN_INDEX; i++)
465 {
466 if (bin == &(to_check[i]))
467 return 1;
468 }
469
470 while (s_bin != NULL)
471 {
472 if (bin == s_bin->bin) return 1;
473 s_bin = s_bin->next;
474 }
476
477 while (to_check != NULL)
478 {
479 if (bin == to_check) return 1;
480 to_check = to_check->next;
481 }
482 return 0;
483}

◆ omMergeStickyBinIntoBin()

void omMergeStickyBinIntoBin ( omBin  sticky_bin,
omBin  into_bin 
)

Definition at line 398 of file omBin.c.

399{
401 !sticky_bin->sticky ||
402 sticky_bin->max_blocks != into_bin->max_blocks ||
403 sticky_bin == into_bin ||
406 {
407#ifndef OM_NDEBUG
409 (! omIsOnGList(om_StickyBins, next, sticky_bin) ? "unknown sticky_bin" :
410 (!sticky_bin->sticky ? "sticky_bin is not sticky" :
411 (sticky_bin->max_blocks != into_bin->max_blocks ? "sticky_bin and into_bin have different block sizes" :
412 (sticky_bin == into_bin ? "sticky_bin == into_bin" :
413 (!omIsKnownTopBin(into_bin, 1) ? "unknown into_bin" :
414 (omIsStickyBin(into_bin) ? "into_bin is sticky" :
415 "unknown sticky_bin error")))))));
416#endif
417 return;
418 }
422
423#if 0
424 if (! omIsStaticBin(into_bin))
425 {
428 }
429#endif
430 omFreeSize(sticky_bin, sizeof(omBin_t));
431#if defined(OM_INTERNAL_DEBUG) && !defined(OM_NDEBUG)
433#endif
434}

◆ omMergeStickyPages()

static void omMergeStickyPages ( omBin  to_bin,
omBin  from_bin 
)
static

Definition at line 267 of file omBin.c.

268{
269#ifdef HAVE_OM_ASSUME
270 int length = omGListLength(to_bin->last_page, prev) +
271 omGListLength(from_bin->last_page, prev);
272#endif
273
274 omBinPage page = from_bin->last_page;
275 omAssume(to_bin->sizeW == from_bin->sizeW);
277
278 if (page == NULL) return;
279 do
280 {
282 if (page->prev == NULL) break;
283 page = page->prev;
284 }
285 while(1);
286
287 if (to_bin->last_page == NULL)
288 {
289 omAssume(to_bin->current_page == om_ZeroPage);
290 to_bin->last_page = from_bin->last_page;
291 to_bin->current_page = from_bin->current_page;
292 return;
293 }
294
295 omAssume(to_bin->current_page != om_ZeroPage &&
296 to_bin->current_page != NULL);
297
298 if (to_bin->current_page->current != NULL)
299 {
300 if (to_bin->current_page->prev == NULL)
301 {
302 from_bin->last_page->next = to_bin->current_page;
303 to_bin->current_page->prev = from_bin->last_page;
304 to_bin->current_page = from_bin->current_page;
305 return;
306 }
307 to_bin->current_page = to_bin->current_page->prev;
308 }
309 else
310 {
311 /* need to reset this here, since new current_page is going to be
312 from_bin->current_page, and only for current_page may we have
313 used_blocks != 0 && current == NULL */
314 to_bin->current_page->used_blocks = 0;
315 }
316
317
318 omAssume(to_bin->current_page != NULL &&
319 to_bin->current_page->current == NULL &&
320 to_bin->current_page->used_blocks == 0);
321
322 from_bin->last_page->next = to_bin->current_page->next;
323 if (to_bin->current_page->next != NULL)
324 to_bin->current_page->next->prev = from_bin->last_page;
325 else
326 {
327 omAssume(to_bin->current_page == to_bin->last_page);
328 to_bin->last_page = from_bin->last_page;
329 }
330 to_bin->current_page->next = page;
331 page->prev = to_bin->current_page;
332 to_bin->current_page = from_bin->current_page;
333
334#ifdef HAVE_OM_ASSUME
335 omAssume(omGListLength(to_bin->last_page, prev) == length);
336#endif
337}

◆ omPrintBinStat()

static void omPrintBinStat ( FILE fd,
omBin  bin,
int  track,
long pages,
long used_blocks,
long free_blocks 
)
static

Definition at line 663 of file omBin.c.

664{
665 if (track)
666 {
667 fputs("T \t \t",fd);
668 }
669 else
670 {
671 fprintf(fd, "%s%ld\t%ld\t", (omIsStaticNormalBin(bin) ? " " :
672 (omIsStickyBin(bin) ? "S" :
673 (omIsTrackBin(bin) ? "T" : "*"))),
674 (long)bin->sizeW, bin->max_blocks);
675 }
676 omGetTotalBinStat(bin, pages, used_blocks, free_blocks);
677 fprintf(fd, "%ld\t%ld\t%ld\n", *pages, *free_blocks, *used_blocks);
678 if (bin->next != NULL && !omIsStickyBin(bin))
679 {
681 while (bin != NULL)
682 {
684 fprintf(fd, " \t \t%ld\t%ld\t%ld\t%d\n", s_pages, s_free_blocks, s_used_blocks,
685 (int) bin->sticky);
686 bin = bin->next;
687 *pages += s_pages;
688 *used_blocks += s_used_blocks;
690 }
691 }
692}

◆ omPrintBinStats()

void omPrintBinStats ( FILE fd)

Definition at line 694 of file omBin.c.

695{
696 int i = OM_MAX_BIN_INDEX;
697 long pages=0, used_blocks=0, free_blocks=0;
700 omBin sticky;
701
702 fputs(" SizeW\tBlocks\tUPages\tFBlocks\tUBlocks\tSticky\n",fd);
703 fflush(fd);
704 while (s_bin != NULL || i >= 0)
705 {
706 if (s_bin == NULL || (i >= 0 && (unsigned long) om_StaticBin[i].max_blocks < (unsigned long) s_bin->bin->max_blocks))
707 {
709 pages += pages_p;
710 used_blocks += used_blocks_p;
712#ifdef OM_HAVE_TRACK
713 if (om_StaticTrackBin[i].current_page != om_ZeroPage)
714 {
716 pages += pages_p;
717 used_blocks += used_blocks_p;
719 }
720#endif
721 i--;
722 }
723 else
724 {
726 pages += pages_p;
727 used_blocks += used_blocks_p;
729 s_bin = s_bin->next;
730 }
731 }
732#ifdef OM_HAVE_TRACK
734 while (s_bin != NULL)
735 {
737 s_bin = s_bin->next;
738 pages += pages_p;
739 used_blocks += used_blocks_p;
741 }
742#endif
743 sticky = om_StickyBins;
744 while (sticky != NULL)
745 {
747 sticky = sticky->next;
748 pages += pages_p;
749 used_blocks += used_blocks_p;
751 }
752 fputs("----------------------------------------\n",fd);
753 fprintf(fd, " \t \t%ld\t%ld\t%ld\n", pages, free_blocks, used_blocks);
754}

◆ omSetStickyAllBinTag()

void omSetStickyAllBinTag ( unsigned long  sticky)

Definition at line 540 of file omBin.c.

541{
543 int i;
544 for (i=0; i<=OM_MAX_BIN_INDEX; i++)
545 {
546 omSetStickyBinTag(&(om_StaticBin[i]), sticky);
547 }
548 while (s_bin != NULL)
549 {
550 omSetStickyBinTag(s_bin->bin, sticky);
551 s_bin = s_bin->next;
552 }
553}

◆ omSetStickyBinTag()

void omSetStickyBinTag ( omBin  bin,
unsigned long  sticky_tag 
)

Definition at line 237 of file omBin.c.

238{
239 omBin s_bin;
241
242 if (s_bin != bin)
243 {
244 omBinPage tc, tl;
245 unsigned long ts;
246
248 ts = bin->sticky;
249 tl = bin->last_page;
250 tc = bin->current_page;
251 bin->sticky = s_bin->sticky;
252 bin->current_page = s_bin->current_page;
253 bin->last_page = s_bin->last_page;
254 s_bin->sticky = ts;
255 s_bin->last_page = tl;
256 s_bin->current_page = tc;
257 }
258}

◆ omUnSetStickyAllBinTag()

void omUnSetStickyAllBinTag ( unsigned long  sticky)

Definition at line 555 of file omBin.c.

556{
558 int i;
559 for (i=0; i<=OM_MAX_BIN_INDEX; i++)
560 {
562 }
563 while (s_bin != NULL)
564 {
565 omUnSetStickyBinTag(s_bin->bin, sticky);
566 s_bin = s_bin->next;
567 }
568}

◆ omUnSetStickyBinTag()

void omUnSetStickyBinTag ( omBin  bin,
unsigned long  sticky 
)

Definition at line 260 of file omBin.c.

261{
262 omAssume(omGetStickyBin(bin, 0) != NULL);
263 if (bin->sticky == sticky)
264 omSetStickyBinTag(bin, 0);
265}

Variable Documentation

◆ om_StickyBins

omBin om_StickyBins = NULL

Definition at line 374 of file omBin.c.