Commit | Line | Data |
---|---|---|
94d7c01a | 1 | /* Functions for memory limit warnings. |
e231fd42 | 2 | Copyright (C) 1990, 1992 Free Software Foundation, Inc. |
94d7c01a JA |
3 | |
4 | This file is part of GNU Emacs. | |
5 | ||
6 | GNU Emacs is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
e231fd42 | 8 | the Free Software Foundation; either version 2, or (at your option) |
94d7c01a JA |
9 | any later version. |
10 | ||
11 | GNU Emacs is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GNU Emacs; see the file COPYING. If not, write to | |
18 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | ||
3b672b8f | 20 | #ifdef emacs |
18160b98 | 21 | #include <config.h> |
94d7c01a | 22 | #include "lisp.h" |
3b672b8f RS |
23 | #endif |
24 | ||
25 | #ifndef emacs | |
26 | #include <stddef.h> | |
27 | typedef size_t SIZE; | |
28 | typedef void *POINTER; | |
29 | #define EXCEEDS_LISP_PTR(x) 0 | |
30 | #endif | |
31 | ||
e231fd42 | 32 | #include "mem-limits.h" |
94d7c01a JA |
33 | |
34 | /* | |
35 | Level number of warnings already issued. | |
36 | 0 -- no warnings issued. | |
37 | 1 -- 75% warning already issued. | |
38 | 2 -- 85% warning already issued. | |
3b672b8f | 39 | 3 -- 95% warning issued; keep warning frequently. |
94d7c01a JA |
40 | */ |
41 | static int warnlevel; | |
42 | ||
43 | /* Function to call to issue a warning; | |
44 | 0 means don't issue them. */ | |
da396c5e | 45 | static void (*warn_function) (); |
94d7c01a | 46 | |
94d7c01a JA |
47 | /* Get more memory space, complaining if we're near the end. */ |
48 | ||
fd065466 RM |
49 | static void |
50 | check_memory_limits () | |
94d7c01a | 51 | { |
134994ae RM |
52 | extern POINTER (*__morecore) (); |
53 | ||
94d7c01a | 54 | register POINTER cp; |
46b3623d RS |
55 | unsigned long five_percent; |
56 | unsigned long data_size; | |
94d7c01a JA |
57 | |
58 | if (lim_data == 0) | |
59 | get_lim_data (); | |
3b672b8f | 60 | five_percent = lim_data / 20; |
94d7c01a JA |
61 | |
62 | /* Find current end of memory and issue warning if getting near max */ | |
fd065466 | 63 | cp = (char *) (*__morecore) (0); |
da396c5e | 64 | data_size = (char *) cp - (char *) data_space_start; |
94d7c01a | 65 | |
da396c5e | 66 | if (warn_function) |
94d7c01a JA |
67 | switch (warnlevel) |
68 | { | |
69 | case 0: | |
3b672b8f | 70 | if (data_size > five_percent * 15) |
94d7c01a JA |
71 | { |
72 | warnlevel++; | |
3b672b8f | 73 | (*warn_function) ("Warning: past 75% of memory limit"); |
94d7c01a JA |
74 | } |
75 | break; | |
76 | ||
77 | case 1: | |
3b672b8f | 78 | if (data_size > five_percent * 17) |
94d7c01a JA |
79 | { |
80 | warnlevel++; | |
3b672b8f | 81 | (*warn_function) ("Warning: past 85% of memory limit"); |
94d7c01a JA |
82 | } |
83 | break; | |
84 | ||
85 | case 2: | |
3b672b8f | 86 | if (data_size > five_percent * 19) |
94d7c01a JA |
87 | { |
88 | warnlevel++; | |
3b672b8f | 89 | (*warn_function) ("Warning: past 95% of memory limit"); |
94d7c01a JA |
90 | } |
91 | break; | |
92 | ||
93 | default: | |
3b672b8f | 94 | (*warn_function) ("Warning: past acceptable memory limits"); |
94d7c01a JA |
95 | break; |
96 | } | |
97 | ||
3b672b8f RS |
98 | /* If we go down below 70% full, issue another 75% warning |
99 | when we go up again. */ | |
100 | if (data_size < five_percent * 14) | |
101 | warnlevel = 0; | |
102 | /* If we go down below 80% full, issue another 85% warning | |
103 | when we go up again. */ | |
104 | else if (warnlevel > 1 && data_size < five_percent * 16) | |
105 | warnlevel = 1; | |
106 | /* If we go down below 90% full, issue another 95% warning | |
107 | when we go up again. */ | |
108 | else if (warnlevel > 2 && data_size < five_percent * 18) | |
109 | warnlevel = 2; | |
110 | ||
111 | if (EXCEEDS_LISP_PTR (cp)) | |
da396c5e | 112 | (*warn_function) ("Warning: memory in use exceeds lisp pointer size"); |
94d7c01a JA |
113 | } |
114 | ||
115 | /* Cause reinitialization based on job parameters; | |
116 | also declare where the end of pure storage is. */ | |
117 | ||
118 | void | |
3b672b8f | 119 | memory_warnings (start, warnfun) |
94d7c01a JA |
120 | POINTER start; |
121 | void (*warnfun) (); | |
122 | { | |
fd065466 | 123 | extern void (* __after_morecore_hook) (); /* From gmalloc.c */ |
94d7c01a JA |
124 | |
125 | if (start) | |
126 | data_space_start = start; | |
3b672b8f RS |
127 | else |
128 | data_space_start = start_of_data (); | |
129 | ||
da396c5e | 130 | warn_function = warnfun; |
fd065466 | 131 | __after_morecore_hook = check_memory_limits; |
94d7c01a | 132 | } |