Mercurial > hg > xemacs-beta
comparison src/vm-limit.c @ 412:697ef44129c6 r21-2-14
Import from CVS: tag r21-2-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:20:41 +0200 |
parents | de805c49cfc1 |
children |
comparison
equal
deleted
inserted
replaced
411:12e008d41344 | 412:697ef44129c6 |
---|---|
43 */ | 43 */ |
44 static int warnlevel; | 44 static int warnlevel; |
45 | 45 |
46 /* Function to call to issue a warning; | 46 /* Function to call to issue a warning; |
47 0 means don't issue them. */ | 47 0 means don't issue them. */ |
48 static void (*warn_function) (const char *); | 48 static void (*warn_function) (CONST char *); |
49 | 49 |
50 /* Get more memory space, complaining if we're near the end. */ | 50 /* Get more memory space, complaining if we're near the end. */ |
51 | 51 |
52 static void | 52 static void |
53 check_memory_limits (void) | 53 check_memory_limits (void) |
55 extern POINTER (*__morecore) (ptrdiff_t size); | 55 extern POINTER (*__morecore) (ptrdiff_t size); |
56 | 56 |
57 POINTER cp; | 57 POINTER cp; |
58 unsigned long five_percent; | 58 unsigned long five_percent; |
59 unsigned long data_size; | 59 unsigned long data_size; |
60 void (*save_warn_fun) (const char *); | |
61 | 60 |
62 if (lim_data == 0) | 61 if (lim_data == 0) |
63 get_lim_data (); | 62 get_lim_data (); |
64 five_percent = lim_data / 20; | 63 five_percent = lim_data / 20; |
65 | 64 |
66 /* Find current end of memory and issue warning if getting near max */ | 65 /* Find current end of memory and issue warning if getting near max */ |
67 cp = (char *) (*__morecore) (0); | 66 cp = (char *) (*__morecore) (0); |
68 data_size = (char *) cp - (char *) data_space_start; | 67 data_size = (char *) cp - (char *) data_space_start; |
69 | 68 |
70 if (warn_function) | 69 if (warn_function) |
71 { | 70 switch (warnlevel) |
72 /* temporarily reset the warn_function to 0 or we will get infinite | 71 { |
73 looping. */ | 72 case 0: |
74 save_warn_fun = warn_function; | 73 if (data_size > five_percent * 15) |
75 warn_function = 0; | 74 { |
76 switch (warnlevel) | 75 warnlevel++; |
77 { | 76 (*warn_function) ("Warning: past 75% of memory limit"); |
78 case 0: | 77 } |
79 if (data_size > five_percent * 15) | 78 break; |
80 { | |
81 warnlevel++; | |
82 (*warn_function) ("Warning: past 75% of memory limit"); | |
83 } | |
84 break; | |
85 | 79 |
86 case 1: | 80 case 1: |
87 if (data_size > five_percent * 17) | 81 if (data_size > five_percent * 17) |
88 { | 82 { |
89 warnlevel++; | 83 warnlevel++; |
90 (*warn_function) ("Warning: past 85% of memory limit"); | 84 (*warn_function) ("Warning: past 85% of memory limit"); |
91 } | 85 } |
92 break; | 86 break; |
93 | 87 |
94 case 2: | 88 case 2: |
95 if (data_size > five_percent * 19) | 89 if (data_size > five_percent * 19) |
96 { | 90 { |
97 warnlevel++; | 91 warnlevel++; |
98 (*warn_function) ("Warning: past 95% of memory limit"); | 92 (*warn_function) ("Warning: past 95% of memory limit"); |
99 } | 93 } |
100 break; | 94 break; |
101 | 95 |
102 default: | 96 default: |
103 (*warn_function) ("Warning: past acceptable memory limits"); | 97 (*warn_function) ("Warning: past acceptable memory limits"); |
104 break; | 98 break; |
105 } | 99 } |
106 warn_function = save_warn_fun; | |
107 } | |
108 | 100 |
109 /* If we go down below 70% full, issue another 75% warning | 101 /* If we go down below 70% full, issue another 75% warning |
110 when we go up again. */ | 102 when we go up again. */ |
111 if (data_size < five_percent * 14) | 103 if (data_size < five_percent * 14) |
112 warnlevel = 0; | 104 warnlevel = 0; |
125 | 117 |
126 /* Cause reinitialization based on job parameters; | 118 /* Cause reinitialization based on job parameters; |
127 also declare where the end of pure storage is. */ | 119 also declare where the end of pure storage is. */ |
128 | 120 |
129 void | 121 void |
130 memory_warnings (void *start, void (*warnfun) (const char *)) | 122 memory_warnings (void *start, void (*warnfun) (CONST char *)) |
131 { | 123 { |
132 extern void (* __after_morecore_hook) (void); /* From gmalloc.c */ | 124 extern void (* __after_morecore_hook) (void); /* From gmalloc.c */ |
133 | 125 |
134 if (start) | 126 if (start) |
135 data_space_start = (char*) start; | 127 data_space_start = start; |
136 else | 128 else |
137 data_space_start = start_of_data (); | 129 data_space_start = start_of_data (); |
138 | 130 |
139 #ifndef _NO_MALLOC_WARNING_ | 131 #ifndef _NO_MALLOC_WARNING_ |
140 warn_function = warnfun; | 132 warn_function = warnfun; |