Mercurial > hg > xemacs-beta
comparison src/sheap.c @ 903:4a27df428c73
[xemacs-hg @ 2002-07-06 05:48:14 by andyp]
sync with 21.4
author | andyp |
---|---|
date | Sat, 06 Jul 2002 05:48:22 +0000 |
parents | 2b6fa2618f76 |
children | 184461bc8de4 |
comparison
equal
deleted
inserted
replaced
902:2fd2239ea63a | 903:4a27df428c73 |
---|---|
25 | 25 |
26 #include <unistd.h> | 26 #include <unistd.h> |
27 #include <sheap-adjust.h> | 27 #include <sheap-adjust.h> |
28 | 28 |
29 #define STATIC_HEAP_BASE 0x800000 | 29 #define STATIC_HEAP_BASE 0x800000 |
30 #define STATIC_HEAP_SLOP 0x40000 | 30 #define STATIC_HEAP_SLOP 0xf0000 |
31 #define STATIC_HEAP_SIZE \ | 31 #define STATIC_HEAP_SIZE \ |
32 (STATIC_HEAP_BASE + SHEAP_ADJUSTMENT + STATIC_HEAP_SLOP) | 32 (STATIC_HEAP_BASE + SHEAP_ADJUSTMENT + STATIC_HEAP_SLOP) |
33 #define BLOCKSIZE (1<<12) | 33 #define BLOCKSIZE (1<<12) |
34 #define ALLOC_UNIT (BLOCKSIZE-1) | 34 #define ALLOC_UNIT (BLOCKSIZE-1) |
35 #define ALLOC_MASK ~((unsigned long)(ALLOC_UNIT)) | 35 #define ALLOC_MASK ~((unsigned long)(ALLOC_UNIT)) |
104 | 104 |
105 return result; | 105 return result; |
106 } | 106 } |
107 | 107 |
108 static void | 108 static void |
109 sheap_adjust_h () | 109 sheap_adjust_h (long adjust) |
110 { | 110 { |
111 FILE *stream = retry_fopen ("sheap-adjust.h", "w"); | 111 FILE *stream = retry_fopen ("sheap-adjust.h", "w"); |
112 | 112 |
113 if (stream == NULL) | 113 if (stream == NULL) |
114 report_file_error ("Opening sheap adjustment file", | 114 report_file_error ("Opening sheap adjustment file", |
115 build_string ("sheap-adjust.h")); | 115 build_string ("sheap-adjust.h")); |
116 | 116 |
117 fprintf (stream, | 117 fprintf (stream, |
118 "/*\tDo not edit this file!\n" | 118 "/*\tDo not edit this file!\n" |
119 "\tAutomatically generated by XEmacs */\n" | 119 "\tAutomatically generated by XEmacs */\n" |
120 "# define SHEAP_ADJUSTMENT (%d)\n", | 120 "# define SHEAP_ADJUSTMENT (%ld)\n", adjust); |
121 ((static_heap_ptr - static_heap_buffer) - STATIC_HEAP_BASE)); | |
122 retry_fclose (stream); | 121 retry_fclose (stream); |
123 } | 122 } |
124 | 123 |
125 void report_sheap_usage (int die_if_pure_storage_exceeded); | 124 void report_sheap_usage (int die_if_pure_storage_exceeded); |
126 void | 125 void |
127 report_sheap_usage (int die_if_pure_storage_exceeded) | 126 report_sheap_usage (int die_if_pure_storage_exceeded) |
128 { | 127 { |
129 int rc = 0; | 128 int rc = 0; |
130 | 129 |
131 Bytecount lost = (STATIC_HEAP_BASE + STATIC_HEAP_SLOP + SHEAP_ADJUSTMENT) | 130 Bytecount lost = STATIC_HEAP_SIZE |
132 - (static_heap_ptr - static_heap_buffer); | 131 - (static_heap_ptr - static_heap_buffer); |
133 char buf[200]; | 132 char buf[200]; |
134 sprintf (buf, "Static heap usage: %ld of %ld", | 133 sprintf (buf, "Static heap usage: %ld of %ld, slop is %ld", |
135 (long) (static_heap_ptr - static_heap_buffer), | 134 (long) (static_heap_ptr - static_heap_buffer), |
136 (long) (STATIC_HEAP_BASE + STATIC_HEAP_SLOP + SHEAP_ADJUSTMENT)); | 135 (long) (STATIC_HEAP_SIZE), |
136 (long) STATIC_HEAP_SLOP); | |
137 | 137 |
138 if (lost > STATIC_HEAP_SLOP) { | 138 if (lost > STATIC_HEAP_SLOP) { |
139 sprintf (buf + strlen (buf), " -- %ldk wasted", (long)(lost/1024)); | 139 sprintf (buf + strlen (buf), " -- %ldk wasted", (long)(lost/1024)); |
140 if (die_if_pure_storage_exceeded) { | 140 if (die_if_pure_storage_exceeded) { |
141 sheap_adjust_h(); | 141 sheap_adjust_h(STATIC_HEAP_SLOP - lost); |
142 sprintf (buf + strlen (buf), " -- reset to %ldk", | |
143 (long) (STATIC_HEAP_SIZE + STATIC_HEAP_SLOP - lost)); | |
142 rc = -1; | 144 rc = -1; |
143 } | 145 } |
144 message ("%s", buf); | 146 message ("%s", buf); |
145 } | 147 } |
146 | 148 |