~ubuntu-branches/ubuntu/karmic/erlang/karmic-security

« back to all changes in this revision

Viewing changes to erts/emulator/beam/erl_bestfit_alloc.c

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-02-15 16:42:52 UTC
  • mfrom: (3.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090215164252-q5x4rcf8a5pbesb1
Tags: 1:12.b.5-dfsg-2
Upload to unstable after lenny is released.

Show diffs side-by-side

added added

removed removed

Lines of Context:
91
91
/* Prototypes of callback functions */
92
92
 
93
93
/* "address order best fit" specific callback functions */
94
 
static Block_t *        aobf_get_free_block     (Allctr_t *, Uint);
 
94
static Block_t *        aobf_get_free_block     (Allctr_t *, Uint,
 
95
                                                 Block_t *, Uint);
95
96
static void             aobf_link_free_block    (Allctr_t *, Block_t *);
96
97
#define                 aobf_unlink_free_block  tree_delete
97
98
 
98
99
/* "best fit" specific callback functions */
99
 
static Block_t *        bf_get_free_block       (Allctr_t *, Uint);
 
100
static Block_t *        bf_get_free_block       (Allctr_t *, Uint,
 
101
                                                 Block_t *, Uint);
100
102
static void             bf_link_free_block      (Allctr_t *, Block_t *);
101
103
static ERTS_INLINE void bf_unlink_free_block    (Allctr_t *, Block_t *);
102
104
 
637
639
#endif
638
640
 
639
641
static Block_t *
640
 
aobf_get_free_block(Allctr_t *allctr, Uint size)
 
642
aobf_get_free_block(Allctr_t *allctr, Uint size,
 
643
                    Block_t *cand_blk, Uint cand_size)
641
644
{
642
645
    BFAllctr_t *bfallctr = (BFAllctr_t *) allctr;
643
646
    RBTree_t *x = bfallctr->root;
644
647
    RBTree_t *blk = NULL;
645
648
    Uint blk_sz;
646
649
 
 
650
    ASSERT(!cand_blk || cand_size >= size);
 
651
 
647
652
    while (x) {
648
653
        blk_sz = BLK_SZ(x);
649
654
        if (blk_sz < size) {
662
667
    ASSERT(blk == check_tree(bfallctr, size));
663
668
#endif
664
669
 
 
670
    if (cand_blk) {
 
671
        blk_sz = BLK_SZ(blk);
 
672
        if (cand_size < blk_sz)
 
673
            return NULL; /* cand_blk was better */
 
674
        if (cand_size == blk_sz && ((void *) cand_blk) < ((void *) blk))
 
675
            return NULL; /* cand_blk was better */
 
676
    }
 
677
 
665
678
    aobf_unlink_free_block(allctr, (Block_t *) blk);
666
679
 
667
680
    return (Block_t *) blk;
782
795
 
783
796
 
784
797
static Block_t *
785
 
bf_get_free_block(Allctr_t *allctr, Uint size)
 
798
bf_get_free_block(Allctr_t *allctr, Uint size,
 
799
                  Block_t *cand_blk, Uint cand_size)
786
800
{
787
801
    BFAllctr_t *bfallctr = (BFAllctr_t *) allctr;
788
802
    RBTree_t *x = bfallctr->root;
789
803
    RBTree_t *blk = NULL;
790
804
    Uint blk_sz;
791
805
 
 
806
    ASSERT(!cand_blk || cand_size >= size);
 
807
 
792
808
    while (x) {
793
809
        blk_sz = BLK_SZ(x);
794
810
        if (blk_sz < size) {
815
831
    }
816
832
#endif
817
833
 
 
834
    if (cand_blk && cand_size <= BLK_SZ(blk))
 
835
        return NULL; /* cand_blk was better */
 
836
 
818
837
    /* Use next block if it exist in order to avoid replacing
819
838
       the tree node */
820
839
    blk = LIST_NEXT(blk) ? LIST_NEXT(blk) : blk;