comparison src/alloc.c @ 55767:ee3a30045908

(marker_blocks_pending_free): New var. (gc_sweep): Store free marker blocks on that list. (Fgarbage_collect): Free them after undo-list cleanup.
author Kim F. Storm <storm@cua.dk>
date Tue, 25 May 2004 11:18:07 +0000
parents 1c3b8ce97c63
children a1bb695e9a0c 85232760f917
comparison
equal deleted inserted replaced
55766:d5fe47c900ee 55767:ee3a30045908
2863 struct marker_block *marker_block; 2863 struct marker_block *marker_block;
2864 int marker_block_index; 2864 int marker_block_index;
2865 2865
2866 union Lisp_Misc *marker_free_list; 2866 union Lisp_Misc *marker_free_list;
2867 2867
2868 /* Marker blocks which should be freed at end of GC. */
2869
2870 struct marker_block *marker_blocks_pending_free;
2871
2868 /* Total number of marker blocks now in use. */ 2872 /* Total number of marker blocks now in use. */
2869 2873
2870 int n_marker_blocks; 2874 int n_marker_blocks;
2871 2875
2872 void 2876 void
2873 init_marker () 2877 init_marker ()
2874 { 2878 {
2875 marker_block = NULL; 2879 marker_block = NULL;
2876 marker_block_index = MARKER_BLOCK_SIZE; 2880 marker_block_index = MARKER_BLOCK_SIZE;
2877 marker_free_list = 0; 2881 marker_free_list = 0;
2882 marker_blocks_pending_free = 0;
2878 n_marker_blocks = 0; 2883 n_marker_blocks = 0;
2879 } 2884 }
2880 2885
2881 /* Return a newly allocated Lisp_Misc object, with no substructure. */ 2886 /* Return a newly allocated Lisp_Misc object, with no substructure. */
2882 2887
4524 } 4529 }
4525 } 4530 }
4526 } 4531 }
4527 4532
4528 nextb = nextb->next; 4533 nextb = nextb->next;
4534 }
4535 }
4536
4537 /* Undo lists have been cleaned up, so we can free marker blocks now. */
4538
4539 {
4540 struct marker_block *mblk;
4541
4542 while ((mblk = marker_blocks_pending_free) != 0)
4543 {
4544 marker_blocks_pending_free = mblk->next;
4545 lisp_free (mblk);
4529 } 4546 }
4530 } 4547 }
4531 4548
4532 /* Clear the mark bits that we set in certain root slots. */ 4549 /* Clear the mark bits that we set in certain root slots. */
4533 4550
5435 struct marker_block **mprev = &marker_block; 5452 struct marker_block **mprev = &marker_block;
5436 register int lim = marker_block_index; 5453 register int lim = marker_block_index;
5437 register int num_free = 0, num_used = 0; 5454 register int num_free = 0, num_used = 0;
5438 5455
5439 marker_free_list = 0; 5456 marker_free_list = 0;
5457 marker_blocks_pending_free = 0;
5440 5458
5441 for (mblk = marker_block; mblk; mblk = *mprev) 5459 for (mblk = marker_block; mblk; mblk = *mprev)
5442 { 5460 {
5443 register int i; 5461 register int i;
5444 int this_free = 0; 5462 int this_free = 0;
5465 } 5483 }
5466 lim = MARKER_BLOCK_SIZE; 5484 lim = MARKER_BLOCK_SIZE;
5467 /* If this block contains only free markers and we have already 5485 /* If this block contains only free markers and we have already
5468 seen more than two blocks worth of free markers then deallocate 5486 seen more than two blocks worth of free markers then deallocate
5469 this block. */ 5487 this block. */
5470 #if 0
5471 /* There may still be pointers to these markers from a buffer's
5472 undo list, so don't free them. KFS 2004-05-21 /
5473 if (this_free == MARKER_BLOCK_SIZE && num_free > MARKER_BLOCK_SIZE) 5488 if (this_free == MARKER_BLOCK_SIZE && num_free > MARKER_BLOCK_SIZE)
5474 { 5489 {
5475 *mprev = mblk->next; 5490 *mprev = mblk->next;
5476 /* Unhook from the free list. */ 5491 /* Unhook from the free list. */
5477 marker_free_list = mblk->markers[0].u_free.chain; 5492 marker_free_list = mblk->markers[0].u_free.chain;
5478 lisp_free (mblk);
5479 n_marker_blocks--; 5493 n_marker_blocks--;
5494
5495 /* It is not safe to free the marker block at this stage,
5496 since there may still be pointers to these markers from
5497 a buffer's undo list. KFS 2004-05-25. */
5498 mblk->next = marker_blocks_pending_free;
5499 marker_blocks_pending_free = mblk;
5480 } 5500 }
5481 else 5501 else
5482 #endif
5483 { 5502 {
5484 num_free += this_free; 5503 num_free += this_free;
5485 mprev = &mblk->next; 5504 mprev = &mblk->next;
5486 } 5505 }
5487 } 5506 }