diff options
author | Karl Heuer <kwzh@gnu.org> | 1994-09-20 05:51:50 +0000 |
---|---|---|
committer | Karl Heuer <kwzh@gnu.org> | 1994-09-20 05:51:50 +0000 |
commit | 1bc280c7e0c96d37e298605d2df497f6a01cbd07 (patch) | |
tree | 7fb7bdbd87b20c516796ff56b20104b25e7d850c /src/ralloc.c | |
parent | c5ef4798a84dd48779fc61663cdf923abdcb2cce (diff) | |
download | emacs-1bc280c7e0c96d37e298605d2df497f6a01cbd07.tar.gz |
(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) /* Interface routines. */ static int use_relocatable_buffers; +static int r_alloc_freeze_level; /* Obtain SIZE bytes of storage from the free pool, or the system, as necessary. If relocatable blocs are in use, this means relocating @@ -370,7 +371,7 @@ r_alloc_sbrk (size) /* Get what we need, plus some extra so we can come here less often. */ SIZE get = size - already_available + extra_bytes; - if (! obtain (get)) + if (r_alloc_freeze_level > 0 || ! obtain (get)) return 0; if (first_bloc) @@ -381,7 +382,8 @@ r_alloc_sbrk (size) bzero (virtual_break_value, get); } /* Can we keep extra_bytes of gap while freeing at least extra_bytes? */ - else if (size < 0 && already_available - size > 2 * extra_bytes) + else if (size < 0 && already_available - size > 2 * extra_bytes + && r_alloc_freeze_level == 0) { /* Ok, do so. This is how many to free. */ SIZE give_back = already_available - size - extra_bytes; @@ -481,6 +483,32 @@ r_re_alloc (ptr, size) return *ptr; } + +/* Disable relocations, after making room for at least SIZE bytes + of non-relocatable heap if possible. The relocatable blocs are + guaranteed to hold still until thawed, even if this means that + malloc must return a null pointer. */ +void +r_alloc_freeze (size) + long size; +{ + /* If already frozen, we can't make any more room, so don't try. */ + if (r_alloc_freeze_level > 0) + size = 0; + /* If we can't get the amount requested, half is better than nothing. */ + while (size > 0 && r_alloc_sbrk (size) == 0) + size /= 2; + ++r_alloc_freeze_level; + if (size > 0) + r_alloc_sbrk (-size); +} + +void +r_alloc_thaw () +{ + if (--r_alloc_freeze_level < 0) + abort (); +} /* The hook `malloc' uses for the function which gets more space from the system. */ |