diff gcc/memory-block.cc @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
line wrap: on
line diff
--- a/gcc/memory-block.cc	Thu Oct 25 07:37:49 2018 +0900
+++ b/gcc/memory-block.cc	Thu Feb 13 11:34:05 2020 +0900
@@ -1,5 +1,5 @@
 /* Shared pool of memory blocks for pool allocators.
-   Copyright (C) 2015-2018 Free Software Foundation, Inc.
+   Copyright (C) 2015-2020 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -28,15 +28,30 @@
 
 memory_block_pool::memory_block_pool () : m_blocks (NULL) {}
 
-/* Return all blocks from free list to the OS.  */
+/* Reduce free list to NUM blocks and return remaining to malloc.  */
 void
-memory_block_pool::clear_free_list ()
+memory_block_pool::reduce_free_list (int num)
 {
-  while (m_blocks)
+  block_list **blocks = &m_blocks;
+
+  /* First skip NUM blocks.  */
+
+  for (;num > 0 && *blocks; num--)
+    blocks = &(*blocks)->m_next;
+
+  if (!*blocks)
+    return;
+
+  /* And free the remainder of them.  */
+
+  block_list *to_free = *blocks;
+  *blocks = NULL;
+
+  while (to_free)
     {
-      block_list *next = m_blocks->m_next;
-      XDELETEVEC (m_blocks);
-      m_blocks = next;
+      block_list *next = to_free->m_next;
+      XDELETEVEC (to_free);
+      to_free = next;
     }
 }
 
@@ -62,3 +77,10 @@
   else
     XDELETEVEC (chunk);
 }
+
+/* Return allocated memory back to malloc (and to system).  */
+void
+memory_block_pool::trim (int num)
+{
+  instance.reduce_free_list (num);
+}