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