diff options
| author | Gareth Rees | 2013-06-03 16:17:28 +0100 |
|---|---|---|
| committer | Gareth Rees | 2013-06-03 16:17:28 +0100 |
| commit | f0def15a48ef784319713ffb13d83fb81e2e51b3 (patch) | |
| tree | c3f08473b669e8a2bf433cba19ddb6f4ed1d7fe0 /mps/code | |
| parent | ca36e1a1479304525892ff81622a6931b678abe2 (diff) | |
| download | emacs-f0def15a48ef784319713ffb13d83fb81e2e51b3.tar.gz emacs-f0def15a48ef784319713ffb13d83fb81e2e51b3.zip | |
Freelistfindlargest() takes a size argument so that the interface matches cbsfindlargest().
New function FreelistFlushToCBS() tries to move all blocks out of a free list and into a CBS.
Copied from Perforce
Change: 182432
ServerID: perforce.ravenbrook.com
Diffstat (limited to 'mps/code')
| -rw-r--r-- | mps/code/freelist.c | 48 | ||||
| -rw-r--r-- | mps/code/freelist.h | 5 |
2 files changed, 45 insertions, 8 deletions
diff --git a/mps/code/freelist.c b/mps/code/freelist.c index 6db2e7e5d01..47e3904adf2 100644 --- a/mps/code/freelist.c +++ b/mps/code/freelist.c | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | * .sources: <design/freelist/>. | 6 | * .sources: <design/freelist/>. |
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | #include "cbs.h" | ||
| 9 | #include "freelist.h" | 10 | #include "freelist.h" |
| 10 | #include "mpm.h" | 11 | #include "mpm.h" |
| 11 | 12 | ||
| @@ -454,10 +455,9 @@ Bool FreelistFindLast(Range rangeReturn, Range oldRangeReturn, | |||
| 454 | 455 | ||
| 455 | 456 | ||
| 456 | Bool FreelistFindLargest(Range rangeReturn, Range oldRangeReturn, | 457 | Bool FreelistFindLargest(Range rangeReturn, Range oldRangeReturn, |
| 457 | Freelist fl, FindDelete findDelete) | 458 | Freelist fl, Size size, FindDelete findDelete) |
| 458 | { | 459 | { |
| 459 | Bool found = FALSE; | 460 | Bool found = FALSE; |
| 460 | Size size = 0; | ||
| 461 | Addr prev, cur, next; | 461 | Addr prev, cur, next; |
| 462 | Addr bestPrev, bestCur; | 462 | Addr bestPrev, bestCur; |
| 463 | 463 | ||
| @@ -469,7 +469,7 @@ Bool FreelistFindLargest(Range rangeReturn, Range oldRangeReturn, | |||
| 469 | prev = NULL; | 469 | prev = NULL; |
| 470 | cur = fl->list; | 470 | cur = fl->list; |
| 471 | while (cur) { | 471 | while (cur) { |
| 472 | if (FreelistBlockSize(fl, cur) > size) { | 472 | if (FreelistBlockSize(fl, cur) >= size) { |
| 473 | found = TRUE; | 473 | found = TRUE; |
| 474 | size = FreelistBlockSize(fl, cur); | 474 | size = FreelistBlockSize(fl, cur); |
| 475 | bestPrev = prev; | 475 | bestPrev = prev; |
| @@ -480,13 +480,11 @@ Bool FreelistFindLargest(Range rangeReturn, Range oldRangeReturn, | |||
| 480 | cur = next; | 480 | cur = next; |
| 481 | } | 481 | } |
| 482 | 482 | ||
| 483 | if (found) { | 483 | if (found) |
| 484 | freelistFindDeleteFromBlock(rangeReturn, oldRangeReturn, fl, size, | 484 | freelistFindDeleteFromBlock(rangeReturn, oldRangeReturn, fl, size, |
| 485 | findDelete, bestPrev, bestCur); | 485 | findDelete, bestPrev, bestCur); |
| 486 | return TRUE; | ||
| 487 | } | ||
| 488 | 486 | ||
| 489 | return FALSE; | 487 | return found; |
| 490 | } | 488 | } |
| 491 | 489 | ||
| 492 | 490 | ||
| @@ -536,6 +534,42 @@ Res FreelistDescribe(Freelist fl, mps_lib_FILE *stream) | |||
| 536 | } | 534 | } |
| 537 | 535 | ||
| 538 | 536 | ||
| 537 | /* freelistFlushIterateMethod -- Iterate method for | ||
| 538 | * FreelistFlushToCBS. Attempst to insert the range into the CBS. | ||
| 539 | */ | ||
| 540 | static Bool freelistFlushIterateMethod(Bool *deleteReturn, Range range, | ||
| 541 | void *closureP, Size closureS) | ||
| 542 | { | ||
| 543 | Res res; | ||
| 544 | RangeStruct newRange; | ||
| 545 | CBS cbs; | ||
| 546 | |||
| 547 | AVER(deleteReturn != NULL); | ||
| 548 | AVERT(Range, range); | ||
| 549 | AVER(closureP != NULL); | ||
| 550 | UNUSED(closureS); | ||
| 551 | |||
| 552 | cbs = closureP; | ||
| 553 | res = CBSInsert(&newRange, cbs, range); | ||
| 554 | if (res == ResOK) { | ||
| 555 | *deleteReturn = TRUE; | ||
| 556 | return TRUE; | ||
| 557 | } else { | ||
| 558 | *deleteReturn = FALSE; | ||
| 559 | return FALSE; | ||
| 560 | } | ||
| 561 | } | ||
| 562 | |||
| 563 | |||
| 564 | void FreelistFlushToCBS(Freelist fl, CBS cbs) | ||
| 565 | { | ||
| 566 | AVERT(Freelist, fl); | ||
| 567 | AVERT(CBS, cbs); | ||
| 568 | |||
| 569 | FreelistIterate(fl, freelistFlushIterateMethod, cbs, 0); | ||
| 570 | } | ||
| 571 | |||
| 572 | |||
| 539 | /* C. COPYRIGHT AND LICENSE | 573 | /* C. COPYRIGHT AND LICENSE |
| 540 | * | 574 | * |
| 541 | * Copyright (C) 2013 Ravenbrook Limited <http://www.ravenbrook.com/>. | 575 | * Copyright (C) 2013 Ravenbrook Limited <http://www.ravenbrook.com/>. |
diff --git a/mps/code/freelist.h b/mps/code/freelist.h index 97b1d2a6420..b16cf1755e3 100644 --- a/mps/code/freelist.h +++ b/mps/code/freelist.h | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | #ifndef freelist_h | 9 | #ifndef freelist_h |
| 10 | #define freelist_h | 10 | #define freelist_h |
| 11 | 11 | ||
| 12 | #include "cbs.h" | ||
| 12 | #include "mpmtypes.h" | 13 | #include "mpmtypes.h" |
| 13 | #include "range.h" | 14 | #include "range.h" |
| 14 | 15 | ||
| @@ -42,7 +43,9 @@ extern Bool FreelistFindFirst(Range rangeReturn, Range oldRangeReturn, | |||
| 42 | extern Bool FreelistFindLast(Range rangeReturn, Range oldRangeReturn, | 43 | extern Bool FreelistFindLast(Range rangeReturn, Range oldRangeReturn, |
| 43 | Freelist fl, Size size, FindDelete findDelete); | 44 | Freelist fl, Size size, FindDelete findDelete); |
| 44 | extern Bool FreelistFindLargest(Range rangeReturn, Range oldRangeReturn, | 45 | extern Bool FreelistFindLargest(Range rangeReturn, Range oldRangeReturn, |
| 45 | Freelist fl, FindDelete findDelete); | 46 | Freelist fl, Size size, FindDelete findDelete); |
| 47 | |||
| 48 | void FreelistFlushToCBS(Freelist fl, CBS cbs); | ||
| 46 | 49 | ||
| 47 | #endif /* freelist.h */ | 50 | #endif /* freelist.h */ |
| 48 | 51 | ||