aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorKaroly Lorentey2004-12-23 16:43:51 +0000
committerKaroly Lorentey2004-12-23 16:43:51 +0000
commit17d51b68fb4e7da4f18eff72c589b7ffc4f9c22c (patch)
treef490c1ccdbd43077ea77f953bc59ca94c2fe810c /src/alloc.c
parent4b89585ee70a1f64543a5851f07cf7e2d89c5c62 (diff)
parent55f4edbcd246d8ea1715687a7aeeb3afe35c0345 (diff)
downloademacs-17d51b68fb4e7da4f18eff72c589b7ffc4f9c22c.tar.gz
emacs-17d51b68fb4e7da4f18eff72c589b7ffc4f9c22c.zip
Merged in changes from CVS trunk.
Patches applied: * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-726 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-727 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-728 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-729 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-730 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-731 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-732 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-733 Update from CVS: man/calc.texi: Fix some TeX definitions. * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-734 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-735 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-736 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-737 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-738 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-739 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-740 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-741 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-742 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-743 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-744 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-745 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-746 Update from CVS * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-75 Merge from emacs--cvs-trunk--0 * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-76 Update from CVS * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-77 Update from CVS git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-277
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c109
1 files changed, 38 insertions, 71 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 4cf5de46d21..7a6a1344d6c 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -99,7 +99,7 @@ extern __malloc_size_t __malloc_extra_blocks;
99 If Emacs sets malloc hooks (! SYSTEM_MALLOC) and the emacs_blocked_* 99 If Emacs sets malloc hooks (! SYSTEM_MALLOC) and the emacs_blocked_*
100 functions below are called from malloc, there is a chance that one 100 functions below are called from malloc, there is a chance that one
101 of these threads preempts the Emacs main thread and the hook variables 101 of these threads preempts the Emacs main thread and the hook variables
102 end up in a inconsistent state. So we have a mutex to prevent that (note 102 end up in an inconsistent state. So we have a mutex to prevent that (note
103 that the backend handles concurrent access to malloc within its own threads 103 that the backend handles concurrent access to malloc within its own threads
104 but Emacs code running in the main thread is not included in that control). 104 but Emacs code running in the main thread is not included in that control).
105 105
@@ -109,7 +109,6 @@ extern __malloc_size_t __malloc_extra_blocks;
109 To prevent that, we only call BLOCK/UNBLOCK from the main thread. */ 109 To prevent that, we only call BLOCK/UNBLOCK from the main thread. */
110 110
111static pthread_mutex_t alloc_mutex; 111static pthread_mutex_t alloc_mutex;
112pthread_t main_thread;
113 112
114#define BLOCK_INPUT_ALLOC \ 113#define BLOCK_INPUT_ALLOC \
115 do \ 114 do \
@@ -201,12 +200,6 @@ extern
201#endif /* VIRT_ADDR_VARIES */ 200#endif /* VIRT_ADDR_VARIES */
202int malloc_sbrk_unused; 201int malloc_sbrk_unused;
203 202
204/* Two limits controlling how much undo information to keep. */
205
206EMACS_INT undo_limit;
207EMACS_INT undo_strong_limit;
208EMACS_INT undo_outer_limit;
209
210/* Number of live and free conses etc. */ 203/* Number of live and free conses etc. */
211 204
212static int total_conses, total_markers, total_symbols, total_vector_size; 205static int total_conses, total_markers, total_symbols, total_vector_size;
@@ -1311,8 +1304,6 @@ uninterrupt_malloc ()
1311 pthread_mutexattr_init (&attr); 1304 pthread_mutexattr_init (&attr);
1312 pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE); 1305 pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
1313 pthread_mutex_init (&alloc_mutex, &attr); 1306 pthread_mutex_init (&alloc_mutex, &attr);
1314
1315 main_thread = pthread_self ();
1316#endif /* HAVE_GTK_AND_PTHREAD */ 1307#endif /* HAVE_GTK_AND_PTHREAD */
1317 1308
1318 if (__free_hook != emacs_blocked_free) 1309 if (__free_hook != emacs_blocked_free)
@@ -4648,13 +4639,48 @@ returns nil, because real GC can't be done. */)
4648 if (abort_on_gc) 4639 if (abort_on_gc)
4649 abort (); 4640 abort ();
4650 4641
4651 EMACS_GET_TIME (t1);
4652
4653 /* Can't GC if pure storage overflowed because we can't determine 4642 /* Can't GC if pure storage overflowed because we can't determine
4654 if something is a pure object or not. */ 4643 if something is a pure object or not. */
4655 if (pure_bytes_used_before_overflow) 4644 if (pure_bytes_used_before_overflow)
4656 return Qnil; 4645 return Qnil;
4657 4646
4647 /* Don't keep undo information around forever.
4648 Do this early on, so it is no problem if the user quits. */
4649 {
4650 register struct buffer *nextb = all_buffers;
4651
4652 while (nextb)
4653 {
4654 /* If a buffer's undo list is Qt, that means that undo is
4655 turned off in that buffer. Calling truncate_undo_list on
4656 Qt tends to return NULL, which effectively turns undo back on.
4657 So don't call truncate_undo_list if undo_list is Qt. */
4658 if (! EQ (nextb->undo_list, Qt))
4659 truncate_undo_list (nextb);
4660
4661 /* Shrink buffer gaps, but skip indirect and dead buffers. */
4662 if (nextb->base_buffer == 0 && !NILP (nextb->name))
4663 {
4664 /* If a buffer's gap size is more than 10% of the buffer
4665 size, or larger than 2000 bytes, then shrink it
4666 accordingly. Keep a minimum size of 20 bytes. */
4667 int size = min (2000, max (20, (nextb->text->z_byte / 10)));
4668
4669 if (nextb->text->gap_size > size)
4670 {
4671 struct buffer *save_current = current_buffer;
4672 current_buffer = nextb;
4673 make_gap (-(nextb->text->gap_size - size));
4674 current_buffer = save_current;
4675 }
4676 }
4677
4678 nextb = nextb->next;
4679 }
4680 }
4681
4682 EMACS_GET_TIME (t1);
4683
4658 /* In case user calls debug_print during GC, 4684 /* In case user calls debug_print during GC,
4659 don't let that cause a recursive GC. */ 4685 don't let that cause a recursive GC. */
4660 consing_since_gc = 0; 4686 consing_since_gc = 0;
@@ -4693,42 +4719,6 @@ returns nil, because real GC can't be done. */)
4693 4719
4694 shrink_regexp_cache (); 4720 shrink_regexp_cache ();
4695 4721
4696 /* Don't keep undo information around forever. */
4697 {
4698 register struct buffer *nextb = all_buffers;
4699
4700 while (nextb)
4701 {
4702 /* If a buffer's undo list is Qt, that means that undo is
4703 turned off in that buffer. Calling truncate_undo_list on
4704 Qt tends to return NULL, which effectively turns undo back on.
4705 So don't call truncate_undo_list if undo_list is Qt. */
4706 if (! EQ (nextb->undo_list, Qt))
4707 nextb->undo_list
4708 = truncate_undo_list (nextb->undo_list, undo_limit,
4709 undo_strong_limit, undo_outer_limit);
4710
4711 /* Shrink buffer gaps, but skip indirect and dead buffers. */
4712 if (nextb->base_buffer == 0 && !NILP (nextb->name))
4713 {
4714 /* If a buffer's gap size is more than 10% of the buffer
4715 size, or larger than 2000 bytes, then shrink it
4716 accordingly. Keep a minimum size of 20 bytes. */
4717 int size = min (2000, max (20, (nextb->text->z_byte / 10)));
4718
4719 if (nextb->text->gap_size > size)
4720 {
4721 struct buffer *save_current = current_buffer;
4722 current_buffer = nextb;
4723 make_gap (-(nextb->text->gap_size - size));
4724 current_buffer = save_current;
4725 }
4726 }
4727
4728 nextb = nextb->next;
4729 }
4730 }
4731
4732 gc_in_progress = 1; 4722 gc_in_progress = 1;
4733 4723
4734 /* clear_marks (); */ 4724 /* clear_marks (); */
@@ -6004,29 +5994,6 @@ prevent garbage collection during a part of the program. */);
6004 doc: /* Non-nil means loading Lisp code in order to dump an executable. 5994 doc: /* Non-nil means loading Lisp code in order to dump an executable.
6005This means that certain objects should be allocated in shared (pure) space. */); 5995This means that certain objects should be allocated in shared (pure) space. */);
6006 5996
6007 DEFVAR_INT ("undo-limit", &undo_limit,
6008 doc: /* Keep no more undo information once it exceeds this size.
6009This limit is applied when garbage collection happens.
6010The size is counted as the number of bytes occupied,
6011which includes both saved text and other data. */);
6012 undo_limit = 20000;
6013
6014 DEFVAR_INT ("undo-strong-limit", &undo_strong_limit,
6015 doc: /* Don't keep more than this much size of undo information.
6016A previous command which pushes the undo list past this size
6017is entirely forgotten when GC happens.
6018The size is counted as the number of bytes occupied,
6019which includes both saved text and other data. */);
6020 undo_strong_limit = 30000;
6021
6022 DEFVAR_INT ("undo-outer-limit", &undo_outer_limit,
6023 doc: /* Don't keep more than this much size of undo information.
6024If the current command has produced more than this much undo information,
6025GC discards it. This is a last-ditch limit to prevent memory overflow.
6026The size is counted as the number of bytes occupied,
6027which includes both saved text and other data. */);
6028 undo_outer_limit = 300000;
6029
6030 DEFVAR_BOOL ("garbage-collection-messages", &garbage_collection_messages, 5997 DEFVAR_BOOL ("garbage-collection-messages", &garbage_collection_messages,
6031 doc: /* Non-nil means display messages at start and end of garbage collection. */); 5998 doc: /* Non-nil means display messages at start and end of garbage collection. */);
6032 garbage_collection_messages = 0; 5999 garbage_collection_messages = 0;