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