diff options
| author | Karl Heuer | 1994-09-20 05:51:50 +0000 |
|---|---|---|
| committer | Karl Heuer | 1994-09-20 05:51:50 +0000 |
| commit | 81bd58e88034ad0f2fce030b0ef2b5169f64ef6a (patch) | |
| tree | fb1846038df70f62c14eff498e9bce18f7584be8 /src/ralloc.c | |
| parent | b6d6a51cfb15fe48d09acd34cf5f91058b175171 (diff) | |
| download | emacs-81bd58e88034ad0f2fce030b0ef2b5169f64ef6a.tar.gz emacs-81bd58e88034ad0f2fce030b0ef2b5169f64ef6a.zip | |
(r_alloc_freeze_level): New variable.
(r_alloc_freeze, r_alloc_thaw): New functions.
(r_alloc_sbrk): Refuse to move blocs, if frozen.
Diffstat (limited to 'src/ralloc.c')
| -rw-r--r-- | src/ralloc.c | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/ralloc.c b/src/ralloc.c index 50b1af8b155..9712c26eb36 100644 --- a/src/ralloc.c +++ b/src/ralloc.c | |||
| @@ -333,6 +333,7 @@ free_bloc (bloc) | |||
| 333 | /* Interface routines. */ | 333 | /* Interface routines. */ |
| 334 | 334 | ||
| 335 | static int use_relocatable_buffers; | 335 | static int use_relocatable_buffers; |
| 336 | static int r_alloc_freeze_level; | ||
| 336 | 337 | ||
| 337 | /* Obtain SIZE bytes of storage from the free pool, or the system, as | 338 | /* Obtain SIZE bytes of storage from the free pool, or the system, as |
| 338 | necessary. If relocatable blocs are in use, this means relocating | 339 | necessary. If relocatable blocs are in use, this means relocating |
| @@ -370,7 +371,7 @@ r_alloc_sbrk (size) | |||
| 370 | /* Get what we need, plus some extra so we can come here less often. */ | 371 | /* Get what we need, plus some extra so we can come here less often. */ |
| 371 | SIZE get = size - already_available + extra_bytes; | 372 | SIZE get = size - already_available + extra_bytes; |
| 372 | 373 | ||
| 373 | if (! obtain (get)) | 374 | if (r_alloc_freeze_level > 0 || ! obtain (get)) |
| 374 | return 0; | 375 | return 0; |
| 375 | 376 | ||
| 376 | if (first_bloc) | 377 | if (first_bloc) |
| @@ -381,7 +382,8 @@ r_alloc_sbrk (size) | |||
| 381 | bzero (virtual_break_value, get); | 382 | bzero (virtual_break_value, get); |
| 382 | } | 383 | } |
| 383 | /* Can we keep extra_bytes of gap while freeing at least extra_bytes? */ | 384 | /* Can we keep extra_bytes of gap while freeing at least extra_bytes? */ |
| 384 | else if (size < 0 && already_available - size > 2 * extra_bytes) | 385 | else if (size < 0 && already_available - size > 2 * extra_bytes |
| 386 | && r_alloc_freeze_level == 0) | ||
| 385 | { | 387 | { |
| 386 | /* Ok, do so. This is how many to free. */ | 388 | /* Ok, do so. This is how many to free. */ |
| 387 | SIZE give_back = already_available - size - extra_bytes; | 389 | SIZE give_back = already_available - size - extra_bytes; |
| @@ -481,6 +483,32 @@ r_re_alloc (ptr, size) | |||
| 481 | 483 | ||
| 482 | return *ptr; | 484 | return *ptr; |
| 483 | } | 485 | } |
| 486 | |||
| 487 | /* Disable relocations, after making room for at least SIZE bytes | ||
| 488 | of non-relocatable heap if possible. The relocatable blocs are | ||
| 489 | guaranteed to hold still until thawed, even if this means that | ||
| 490 | malloc must return a null pointer. */ | ||
| 491 | void | ||
| 492 | r_alloc_freeze (size) | ||
| 493 | long size; | ||
| 494 | { | ||
| 495 | /* If already frozen, we can't make any more room, so don't try. */ | ||
| 496 | if (r_alloc_freeze_level > 0) | ||
| 497 | size = 0; | ||
| 498 | /* If we can't get the amount requested, half is better than nothing. */ | ||
| 499 | while (size > 0 && r_alloc_sbrk (size) == 0) | ||
| 500 | size /= 2; | ||
| 501 | ++r_alloc_freeze_level; | ||
| 502 | if (size > 0) | ||
| 503 | r_alloc_sbrk (-size); | ||
| 504 | } | ||
| 505 | |||
| 506 | void | ||
| 507 | r_alloc_thaw () | ||
| 508 | { | ||
| 509 | if (--r_alloc_freeze_level < 0) | ||
| 510 | abort (); | ||
| 511 | } | ||
| 484 | 512 | ||
| 485 | /* The hook `malloc' uses for the function which gets more space | 513 | /* The hook `malloc' uses for the function which gets more space |
| 486 | from the system. */ | 514 | from the system. */ |